mirror of
https://github.com/zoriya/Magical-Garden.git
synced 2025-12-05 23:06:17 +00:00
Adding mission possibility check.
This commit is contained in:
@@ -43,9 +43,10 @@ public class Mission : MonoBehaviour {
|
||||
{
|
||||
Objectifs = new Dictionary<TreeType, int>();
|
||||
int loop = Random.Range(easy, hard);
|
||||
int usedTilesNb = 0;
|
||||
for (int i = 0; i < loop; i++)
|
||||
{
|
||||
AddTree();
|
||||
AddTree(usedTilesNb, out usedTilesNb);
|
||||
}
|
||||
string mission = null;
|
||||
foreach (KeyValuePair<TreeType,int> i in Objectifs)
|
||||
@@ -70,10 +71,19 @@ public class Mission : MonoBehaviour {
|
||||
|
||||
if (Objectifs.ContainsKey(manager.items[i].type))
|
||||
{
|
||||
int minCount;
|
||||
Objectifs.TryGetValue(manager.items[i].type, out minCount);
|
||||
if(manager.items[i].count < minCount)
|
||||
manager.items[i].count += minCount;
|
||||
if(manager.items[i].type != TreeType.AppleTree)
|
||||
{
|
||||
manager.items[(int)TreeType.Cactus - 1].count += 5;
|
||||
manager.items[(int)TreeType.ThirstyTree - 1].count += 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
int minCount;
|
||||
Objectifs.TryGetValue(manager.items[i].type, out minCount);
|
||||
if (manager.items[i].count < minCount)
|
||||
manager.items[i].count += minCount;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -90,14 +100,23 @@ public class Mission : MonoBehaviour {
|
||||
return mission;
|
||||
}
|
||||
|
||||
private void AddTree()
|
||||
private void AddTree(int usedTilesNb, out int usedTiles)
|
||||
{
|
||||
usedTiles = usedTilesNb;
|
||||
TreeItem[] trees = items.Where(x => !Objectifs.ContainsKey(x.type) && x.type != TreeType.Nothing).ToArray();
|
||||
if (trees.Length > 0)
|
||||
{
|
||||
int i = Random.Range(0, trees.Length);
|
||||
TreeType type = trees[i].type;
|
||||
int number = Random.Range(items[i].maxInstanceForWin / 2 + 1, items[i].maxInstanceForWin);
|
||||
usedTiles += number;
|
||||
|
||||
if (usedTiles > 22)
|
||||
{
|
||||
GetComponent<InventoryManager>().items[(int)TreeType.SwapTree - 1].count += 3;
|
||||
return;
|
||||
}
|
||||
|
||||
Objectifs.Add(type, number);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user