public static void ReportStatus(VillageState status, ByteArray byteArray) { byteArray.Reset(); byteArray.WriteHeader(); byteArray.writeInt(EnumVillageReportMethods.CLIENT_REPORTSTATUS_HASH); byteArray.EncryptKey = EnumVillageReportMethods.CLIENT_REPORTSTATUS_HASH; byteArray.CRC = 0; byteArray.writeDynamicsInt(ByteArray.globalSeq); status.WriteToByteArray(byteArray); ++ByteArray.globalSeq; byteArray.writeIntNCRC(byteArray.CRC); byteArray.EncryptKey = 0; }
public static ByteArray ReportStatus(VillageState status) { ByteArray byteArray = new ByteArray(); byteArray.writeInt(EnumVillageReportMethods.CLIENT_REPORTSTATUS_HASH); byteArray.EncryptKey = EnumVillageReportMethods.CLIENT_REPORTSTATUS_HASH; byteArray.CRC = 0; byteArray.writeDynamicsInt(ByteArray.globalSeq); status.WriteToByteArray(byteArray); ++ByteArray.globalSeq; byteArray.writeInt(byteArray.CRC); byteArray.EncryptKey = 0; return(byteArray); }
private static bool OnReportStatus(ByteArray byteArray, IVillageReportClientService clientService) { VillageState status = new VillageState(); status.ReadFromByteArray(byteArray); int crc = byteArray.readIntNCRC(); if (crc == byteArray.CRC) { clientService.OnReportStatus(ref status); } byteArray.Recycle(); return(true); }
private static string ParseReportStatus(ByteArray byteArray) { StringBuilder sb = new StringBuilder(); sb.Append("ReportStatus("); sb.Append("status : VillageState"); sb.Append(")\r\n{\r\n"); int crc = byteArray.readIntNCRC(); // parse global seq VillageState status = new VillageState(); status.ReadFromByteArray(byteArray); sb.AppendFormat(@"status = ""{0}""", status); sb.Append("}"); return(sb.ToString()); }
// Update is called once per frame void Update() { if (houses.Length == 0) { state = VillageState.NUETRAL; } if (state != VillageState.NUETRAL) { devotionCounter += Time.deltaTime; forgetCounter += Time.deltaTime; } //else { positiveWorship.GetComponent <Renderer>().enabled = false; negativeWorship.GetComponent <Renderer>().enabled = false; doublePositiveWorship.GetComponent <Renderer>().enabled = false; doubleNegativeWorship.GetComponent <Renderer>().enabled = false; alertBubble.GetComponent <Renderer>().enabled = false; if (state == VillageState.BURNING) { audioSource.Play(); Destroy(villageGround); villageGround = Instantiate(badCircles[circleIndex], transform.position, transform.rotation) as GameObject; villageGround.transform.SetParent(this.transform); if (goodDevotion + badDevotion != 0) { float scaleAmount = (badDevotion - goodDevotion) / (goodDevotion + badDevotion) * maxScaleGround; scaleAmount = (1 - ((MAX_ENCOUNTER - timesEncounter) * forgetDevotion + forgetCounter) / (forgetDevotion * MAX_ENCOUNTER)) * maxScaleGround; if (scaleAmount > 0) { villageGround.transform.localScale = new Vector3(scaleAmount, scaleAmount, 1); } } if (timesEncounter > 1) { doubleNegativeWorship.GetComponent <Renderer>().enabled = true; Color c = doubleNegativeWorship.GetComponent <Renderer>().material.color; c.a = devotionCounter / devotionIncrement; doubleNegativeWorship.GetComponent <Renderer>().material.color = c; } else if (timesEncounter == 1) { negativeWorship.GetComponent <Renderer>().enabled = true; Color c = negativeWorship.GetComponent <Renderer>().material.color; c.a = devotionCounter / devotionIncrement; negativeWorship.GetComponent <Renderer>().material.color = c; } } else if (state == VillageState.WORSHIPPING) { audioSource.Stop(); Destroy(villageGround); villageGround = Instantiate(goodCircles[circleIndex], transform.position, transform.rotation) as GameObject; villageGround.transform.SetParent(this.transform); if (goodDevotion + badDevotion != 0) { float scaleAmount = (goodDevotion - badDevotion) / (goodDevotion + badDevotion) * maxScaleGround; scaleAmount = (1 - ((MAX_ENCOUNTER - timesEncounter) * forgetDevotion + forgetCounter) / (forgetDevotion * MAX_ENCOUNTER)) * maxScaleGround; if (scaleAmount > 0) { villageGround.transform.localScale = new Vector3(scaleAmount, scaleAmount, 1); } } if (timesEncounter > 1) { doublePositiveWorship.GetComponent <Renderer>().enabled = true; Color c = doublePositiveWorship.GetComponent <Renderer>().material.color; c.a = devotionCounter / devotionIncrement; doublePositiveWorship.GetComponent <Renderer>().material.color = c; } else if (timesEncounter == 1) { positiveWorship.GetComponent <Renderer>().enabled = true; Color c = positiveWorship.GetComponent <Renderer>().material.color; c.a = devotionCounter / devotionIncrement; positiveWorship.GetComponent <Renderer>().material.color = c; } } else { audioSource.Stop(); Destroy(villageGround); } int houseCount = 0; int burningHouses = 0; for (int i = 0; i < houses.Length; i++) { houseCount++; if (houses[i] == null) { cleanUpHouses(); // burn other house if (houses.Length != 0) { houses[Random.Range(0, houses.Length)].GetComponent <HouseScript>().isburning = true; } //Update(); //return; } else if (timesEncounter < 1 && houses[i].GetComponent <HouseScript>().isburning) { state = VillageState.BURNING; timesEncounter = 1; forgetCounter = 0; } else if (houses[i].GetComponent <HouseScript>().isburning) { burningHouses++; } else if (state == VillageState.WORSHIPPING) { houses[i].GetComponent <HouseScript>().isWorshipping = true; } else { houses[i].GetComponent <HouseScript>().isWorshipping = false; } } // Interacting with the lake if (lake != null) { if (lake.GetComponent <LakeScript>().isFilled) { houseCounter += Time.deltaTime; /*if(state == VillageState.NUETRAL && houseCount > 0){ * state = VillageState.WORSHIPPING; * timesEncounter = 1; * forgetCounter = 0; * } else */if (state == VillageState.NUETRAL && wasFilling) { state = VillageState.WORSHIPPING; timesEncounter = 1; forgetCounter = 0; wasFilling = false; } if (houseCount < maxHouses && houseCounter > makeHouseSeconds && state == VillageState.WORSHIPPING) { houseCounter = 0; Debug.Log("About to make house"); // make new House makeNewHouse(lake); } } else if (lake.GetComponent <LakeScript>().isFilling&& state == VillageState.NUETRAL) { wasFilling = true; } } else { //throw new ExitGUIException(); } if (updatedDevotion) { //Pop up text here textCounter += Time.deltaTime; } if (textCounter > textSeconds) { textCounter = 0; updatedDevotion = false; } if (devotionCounter > devotionIncrement) { devotionCounter = 0; updatedDevotion = true; if (state == VillageState.BURNING) { pointsGained = devotionRateBad * houses.Length * timesEncounter * burningHouses; badDevotion += (int)pointsGained; } else if (state == VillageState.WORSHIPPING) { pointsGained = devotionRateGood * houses.Length * timesEncounter; goodDevotion += (int)pointsGained; } else { Debug.Log("ERROR: THIS IS BAD"); } } if (forgetCounter > forgetDevotion) { timesEncounter--; Debug.Log(timesEncounter); timesEncounter = Mathf.Max(timesEncounter, 0); forgetCounter = 0; if (timesEncounter < 1) { state = VillageState.NUETRAL; } } //interact with lava flow nearby //NOTE: This only works when max_encounter is 2 GameObject lavaHead = CameraControl.myPlay; if (lavaHead != null) { if (nearby(lavaHead.transform.position, radiusNear)) { if (state != VillageState.NUETRAL) { alertBubble.GetComponent <Renderer>().enabled = true; timesEncounter++; timesEncounter = Mathf.Min(timesEncounter, MAX_ENCOUNTER); forgetCounter = 0; } else if (lake != null && lake.GetComponent <LakeScript>().isFilled) { /*state = VillageState.WORSHIPPING; * timesEncounter = 1; * forgetCounter = 0;*/ } } } //Color color = villageGround.GetComponent<SpriteRenderer>().color; }