forked from CommandoCorey/RiseFromTheAshes
/
BuildTask.cs
145 lines (116 loc) · 3.96 KB
/
BuildTask.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "Build Task", menuName = "Ai Task/Construct Building", order = 1)]
public class BuildTask : AiTask
{
public Building buildingToConstruct;
public int priorityScore = 10;
public bool autoSelectPlaceholder = true;
[Range(0, 7)]
public int placeholderNumber;
protected Building instance;
public override string TaskDescription {
get => "Build " + buildingToConstruct.buildingName;
}
public override string ActiveTaskDescription
{
get => "Constructing " + buildingToConstruct.buildingName + "... ";
}
public override object Clone()
{
var clonedTask = new BuildTask();
clonedTask.buildingToConstruct = buildingToConstruct;
clonedTask.autoSelectPlaceholder = autoSelectPlaceholder;
clonedTask.placeholderNumber = placeholderNumber;
clonedTask.instance = instance;
return clonedTask;
}
/*
public override int GetSteelCost()
{
return buildingToConstruct.steelCost;
}*/
public override bool CanPerform()
{
var ai = FindObjectOfType<AiPlayer>();
int steel = ResourceManager.Instance.aiResources[0].currentAmount;
if (steel >= buildingToConstruct.steelCost)
{
if (ai.PlaceHoldersLeft)
return true;
else
taskStatus = "No ghost buildings left";
}
else
{
taskStatus = "Not enough steel";
}
return false;
}
public override bool PerformTask()
{
if (FindObjectOfType<AiPlayer>())
{
var ai = FindObjectOfType<AiPlayer>();
/*
if(buildingToConstruct.tag == "Outpost" && !ai.OutpostPlaceholdersLeft)
{
taskStatus = "No outposts discovered";
return false;
}
else */if (!ai.PlaceHoldersLeft)
{
taskStatus = "No placeholders left";
Debug.LogWarning("There are no more placeholders to construct the next building");
return false;
}
Transform ghostBuilding;
// check if building is an outpost
/* if (buildingToConstruct.tag == "Outpost")
{
if (autoSelectPlaceholder)
ghostBuilding = ai.GetOutpostPlaceholder(0);
else
ghostBuilding = ai.GetPlaceholder(placeholderNumber);
}
else
{*/
if (autoSelectPlaceholder)
ghostBuilding = ai.GetNextPlaceholder();
else
ghostBuilding = ai.GetPlaceholder(placeholderNumber);
//}
ai.ConstructBuilding(ghostBuilding, buildingToConstruct, this);
//taskStatus = "Constructing building";
return true;
}
else if (FindObjectOfType<SimpleAiPlayer>())
{
var ai = FindObjectOfType<SimpleAiPlayer>();
if (!ai.PlaceHoldersLeft)
{
taskStatus = "No placeholders left";
Debug.LogWarning("There are no more placeholders to construct the next building");
return false;
}
Transform ghostBuilding;
if (autoSelectPlaceholder)
ghostBuilding = ai.GetPlaceholder(0);
else
ghostBuilding = ai.GetPlaceholder(placeholderNumber);
ai.ConstructBuilding(ghostBuilding, buildingToConstruct, this);
//taskStatus = "Constructing building";
return true;
}
return false;
}
public void SetBuildingInstance(Building building)
{
instance = building;
}
public override bool IsComplete()
{
return instance.IsBuilding == false;
}
}