public static void readPlagues(List <Plague> plagueList) { TextAsset file = Resources.Load("json/plagues", typeof(TextAsset)) as TextAsset; if (file != null) { JSONNode node = JSON.Parse(file.text); for (int j = 0; j < node["PLAGUES"].Count; ++j) { JSONNode nodeDeeper = node["PLAGUES"][j]; int id = nodeDeeper ["ID"].AsInt; string name = Dictionary.getString(nodeDeeper["NAME"].Value); string description = Dictionary.getString(nodeDeeper["DESCRIPTION"].Value); string img = nodeDeeper["IMAGE"].Value; int monthIn = nodeDeeper ["MONTH_IN"].AsInt; int monthOut = nodeDeeper ["MONTH_OUT"].AsInt; int baseDmg = nodeDeeper ["BASE_DMG"].AsInt; Plague plg = new Plague(id, name, description, img, monthIn, monthOut, baseDmg); plagueList.Add(plg); } } else { Debug.Log("File json/plagues not loaded"); } }
void executePlague(int id) { plagueHappening = true; activePlague = pm.getPlague(id); plagueInitialDay = tm.getCurrentDay(); remainingChunks = 0; WorldTerrain wt = WorldTerrain.GetInstance(); int tilesPerChunk = wt.getTotalTilesInAChunk(); visitedChunk = new bool[wt.getNumberOfChunks()]; for (int i = 0; i < wt.getNumberOfChunks(); i++) { visitedChunk [i] = true; } for (int i = 0; i < wt.getNumberOfChunks(); i++) { int rnd = Random.Range(1, 3); if ((rnd < 3 || remainingChunks == 0) && wt.isChunkPlanted(i)) { visitedChunk[i] = false; remainingChunks++; uint randomTile = (uint)((UnityEngine.Random.value) * (float)(tilesPerChunk - 1)); wt.updatePlagueStateInTile(i, (int)randomTile, plagueType(activePlague.getID())); } } if (remainingChunks == 0) { cleanPlague(); } else { activePlague.setActive(true); } }
void cleanPlague() { activePlague.setActive(false); activePlague = null; plagueHappening = false; //WorldTerrain wt = WorldTerrain.GetInstance(); for (int i = 0; i < visitedChunk.Length; i++) { visitedChunk [i] = true; } }
int checkPlagues() { for (int i = 0; i < plagueCount; i++) { Plague p = pm.getPlague(i); if (p.alreadyHappened()) { continue; } if (p.getMonthIn() > tm.getCurrentMonth() + 1 || p.getMonthOut() < tm.getCurrentMonth() + 1) { continue; } int prob = Random.Range(1, 100); if (prob <= p.getSpawnChance() - InvestigationManager.GetInstance().getPlagueDecreaseBonus()) { return(i); } } return(-1); }