Skip to content

Commit

Permalink
Economy (#36)
Browse files Browse the repository at this point in the history
* Resources #1

* Resource production
  • Loading branch information
szczerrzuja authored Nov 22, 2023
1 parent 4c94ffa commit ceacacd
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.preferCSharpExtension": true
}
3 changes: 3 additions & 0 deletions ProjectTowerDefence/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "ProjectTowerDefence.sln"
}
4 changes: 4 additions & 0 deletions ProjectTowerDefence/Assets/Prefabs/InGameUI.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -3913,6 +3913,10 @@ MonoBehaviour:
m_EditorClassIdentifier:
upgradeButton: {fileID: 6807917380029169322}
destroyButton: {fileID: 6807917381556369733}
Gold: {fileID: 6807917380352134223}
Wood: {fileID: 6807917380677331075}
Supply: {fileID: 6807917381460935671}
Mana: {fileID: 6807917381179926136}
--- !u!1 &6807917381641104908
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5158832432637384124
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5158832432637384122}
- component: {fileID: 5158832432637384123}
m_Layer: 0
m_Name: ResourceController
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5158832432637384122
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5158832432637384124}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -55.978725, y: 45.228745, z: -7.8830934}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5158832432637384123
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5158832432637384124}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 857dc9da19c3cfa4ca36b1851817dffb, type: 3}
m_Name:
m_EditorClassIdentifier:
resources:
- name: Gold
ResourceID: 0
amount: 20
MaxAmmount: 0
- name: Wood
ResourceID: 1
amount: 10
MaxAmmount: 0
- name: Supply
ResourceID: 2
amount: 0
MaxAmmount: 100
- name: Mana
ResourceID: 3
amount: 10
MaxAmmount: 300

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 80 additions & 38 deletions ProjectTowerDefence/Assets/Scenes/Level_3.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38661,6 +38661,14 @@ PrefabInstance:
propertyPath: levelController
value:
objectReference: {fileID: 522010061}
- target: {fileID: 6807917381595984780, guid: f51816d589bc4bc499ac32056d6e0ea5, type: 3}
propertyPath: ResourceBar
value:
objectReference: {fileID: 1980655408}
- target: {fileID: 6807917381595984780, guid: f51816d589bc4bc499ac32056d6e0ea5, type: 3}
propertyPath: ownerResources
value:
objectReference: {fileID: 710165580}
- target: {fileID: 6807917381595984781, guid: f51816d589bc4bc499ac32056d6e0ea5, type: 3}
propertyPath: m_Name
value: InGameUI
Expand Down Expand Up @@ -42319,49 +42327,17 @@ Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 9414ce5147538c14d9577e2862009f48, type: 3}
m_PrefabInstance: {fileID: 710124205}
m_PrefabAsset: {fileID: 0}
--- !u!1 &710165579
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 710165581}
- component: {fileID: 710165580}
m_Layer: 0
m_Name: ResourceController
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &710165580
--- !u!114 &710165580 stripped
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 5158832432637384123, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
m_PrefabInstance: {fileID: 5158832433009381879}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 710165579}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 857dc9da19c3cfa4ca36b1851817dffb, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &710165581
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 710165579}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -55.978725, y: 45.228745, z: -7.8830934}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &710168714
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -62587,10 +62563,14 @@ MonoBehaviour:
m_EditorClassIdentifier:
timeToProduction: 2
produced_Resources:
- ResourceID: 0
- name:
ResourceID: 0
amount: 10
- ResourceID: 2
MaxAmmount: 0
- name:
ResourceID: 2
amount: 2
MaxAmmount: 0
owner: {fileID: 710165580}
--- !u!136 &1043941204
CapsuleCollider:
Expand Down Expand Up @@ -118145,6 +118125,11 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 9c1e58677d1f47945a8389d0390172b7, type: 3}
--- !u!1 &1980655408 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 6807917381872425784, guid: f51816d589bc4bc499ac32056d6e0ea5, type: 3}
m_PrefabInstance: {fileID: 644626409}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &1981525064
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -129071,6 +129056,63 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 98ba2af8312fabc43ab5a4b0dd2ac153, type: 3}
--- !u!1001 &5158832433009381879
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5158832432637384122, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
propertyPath: m_LocalPosition.x
value: -55.978725
objectReference: {fileID: 0}
- target: {fileID: 5158832432637384122, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
propertyPath: m_LocalPosition.y
value: 45.228745
objectReference: {fileID: 0}
- target: {fileID: 5158832432637384122, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
propertyPath: m_LocalPosition.z
value: -7.8830934
objectReference: {fileID: 0}
- target: {fileID: 5158832432637384122, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5158832432637384122, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5158832432637384122, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5158832432637384122, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5158832432637384122, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
propertyPath: m_RootOrder
value: 8
objectReference: {fileID: 0}
- target: {fileID: 5158832432637384122, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5158832432637384122, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5158832432637384122, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5158832432637384124, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
propertyPath: m_Name
value: ResourceController
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: a0447336b0a5db94b91f74e3465bf34e, type: 3}
--- !u!1001 &6322297430338665782
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
63 changes: 44 additions & 19 deletions ProjectTowerDefence/Assets/Scripts/Buildings/ResourcesController.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using TMPro.Examples;
using UnityEngine;
using System;
/*
TODO: update surowców w gui, update surowców w programie, lista budynków do "ściągania" surowców,
zarządzanie listą budynków do surowca
*/
public class ResourcesController : MonoBehaviour
{

List<Resource> resources = new List<Resource>();
[SerializeField] private List<Resource> resources = new List<Resource>();
void Start()
{

for(int i=0; i< (int)Resource.ResourcesTypes.EndNumber; i++)
for(int i=0; i< (int)Resource.ResourcesTypes.End; i++)
{
resources.Add(new Resource((uint)i));
}
Expand All @@ -24,51 +26,74 @@ public void AddResourcesAmount(List<Resource> res)
{
for(int i=0; i<res.Count; i++)
{
if(res[i].ResourceID < resources.Count)
resources[(int)res[i].ResourceID].amount += res[i].amount;
if(res[i].ResourceID < resources.Count){
//programowanie bezgałęziowe, zamiast if else if zostąło uzyte zwykłe mnożenie
bool condition = resources[(int)res[i].ResourceID].MaxAmmount == 0;
resources[(int)res[i].ResourceID].amount += res[i].amount * Convert.ToInt32(condition) +
Mathf.Clamp(res[i].amount, -99999, resources[(int)res[i].ResourceID].MaxAmmount-resources[(int)res[i].ResourceID].amount) * Convert.ToInt32(!condition);
}
}

string tmp = resources.Count.ToString()+"\n";
for(int i=0; i<resources.Count;i++)
{
tmp+= resources[i].ResourceID.ToString()+" : "+ resources[i].amount.ToString()+"\n";
}

Debug.Log("resources added");
}
public void addSingleResource(Resource res)
public void AddSingleResource(Resource res)
{
if(res.ResourceID < resources.Count)
{
resources[(int)res.ResourceID].amount += res.amount;
//programowanie bezgałęziowe, zamiast if else if zostąło uzyte zwykłe mnożenie
bool condition = resources[(int)res.ResourceID].MaxAmmount == 0;
resources[(int)res.ResourceID].amount += res.amount*Convert.ToInt32(condition) +
Mathf.Clamp(res.amount, -99999, resources[(int)res.ResourceID].MaxAmmount-resources[(int)res.ResourceID].amount) * Convert.ToInt32(!condition);

}
}
public ref List<Resource> GetResourcesRef() {
return ref resources;
}
}

[System.Serializable]
/*
Helper class to contain resource in other class
*/
public class Resource{

/*
Tutaj wrzucasz wszystkie rzeczy które mają być w grze. Ostatni musi być EndNumber
*/
public enum ResourcesTypes {
public enum ResourcesTypes {
Gold = 0,
Wood,
Supply,
Mana,
EndNumber
End
}
public string name;
/*
Tutaj wrzucasz wszystkie rzeczy które mają być w grze. Ostatni musi być End
*/
public uint ResourceID;
public float amount;
//jezeli ta wartość jest równa 0, to maksymalna wartośc jest równa nieskończoność
public int MaxAmmount;

/*
Konsxtruktor, gdzie wartość startowa będzie równa 0
*/
public Resource(uint resourceID)
{
ResourceID = resourceID;
amount = 0.0f;
MaxAmmount = 0;
}
/*
Konsturktor z wartością startową
*/
public Resource(uint resourceID, float startAmount)
{
ResourceID = resourceID;
amount = startAmount;
MaxAmmount = 0;
}
public Resource(uint resourceID, float startAmount, int maxAmmount)
{
ResourceID = resourceID;
amount = startAmount;
MaxAmmount = maxAmmount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ public class ResourcesProduction : MonoBehaviour {
[SerializeField] float timeToProduction;
[SerializeField] List<Resource> produced_Resources;
[SerializeField] ResourcesController owner;


void Start()
{
if(owner!=null)
{
Debug.Log("Mam wadce");
StartCoroutine(ProduceResource());
}
}
Expand All @@ -24,7 +25,7 @@ IEnumerator ProduceResource(){
yield return new WaitForSecondsRealtime(timeToProduction);
if(owner != null)
{
Debug.Log("Here i am");

StartCoroutine(ProduceResource());
owner.AddResourcesAmount(produced_Resources);
}
Expand Down
Loading

0 comments on commit ceacacd

Please sign in to comment.