public void AddMyFaction(byte[] packet) { byte factionIndex = 255; // invoke runtime error? NewPackets.PopByteHeader(packet, out factionIndex); // This is my faction! myFactionID = factionIndex; print("ADDING MY FACTION " + myFactionID); if (FactionEntities[factionIndex, 0] != null) { Debug.Log("SETTING CAM POSITION"); Camera.main.transform.position = FactionEntities[factionIndex, 0].transform.position - new Vector3(0, 0, -10); } }
public void RecieveFactionUpdate(byte[] packet) { byte factionIndex = 255; // invoke runtime error? packet = NewPackets.PopByteHeader(packet, out factionIndex); if (factionIndex == myFactionID) { NewPackets.FactionUpdate fUp = new NewPackets.FactionUpdate(packet); if (1 < fUp.credits - Credits) { GameObject.FindObjectOfType <AudioManager>().PlaySell(); } if (Credits > fUp.credits) { GameObject.FindObjectOfType <AudioManager>().PlayBuy(); } Credits.Value = fUp.credits; CreditCounter.text = "" + Credits; } }
public void RecieveEntityUpdate(byte[] packet) { // Get the faction index from the header byte factionIndex = 0; packet = NewPackets.PopByteHeader(packet, out factionIndex); // Deserialize NewPackets.EntityUpdate entityUpdate = new NewPackets.EntityUpdate(packet); if (FactionEntities[factionIndex, entityUpdate.unitIndex] == null) { // Implicitly populate faction entities switch (entityUpdate.unitType) { // Units case Constants.Entities. Miner.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(factionIndex == 1 ? Faction1Miner : Faction2Miner).GetComponent <Entity>(); break; case Constants.Entities. Digger.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(factionIndex == 1 ? Faction1Digger : Faction2Digger).GetComponent <Entity>(); break; case Constants.Entities. Soldier.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(factionIndex == 1 ? Faction1Soldier : Faction2Soldier).GetComponent <Entity>(); break; case Constants.Entities. Hauler.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(factionIndex == 1 ? Faction1Hauler : Faction2Hauler).GetComponent <Entity>(); break; //... // Deployables case Constants.Entities. QuickSand.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(CementBombEntityPrefab).GetComponent <Entity>(); break; case Constants.Entities. TimeBomb.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(TimeBombEntityPrefab).GetComponent <Entity>(); break; case Constants.Entities. ProximityMine.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(MineEntityPrefab).GetComponent <Entity>(); break; case Constants.Entities. GasBomb.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(GasBombEntityPrefab).GetComponent <Entity>(); break; case Constants.Entities. HealStation.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(HealStationEntityPrefab).GetComponent <Entity>(); break; case Constants.Entities. SonicBomb.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(SonicBombEntityPrefab).GetComponent <Entity>(); break; case Constants.Entities. AntimatterBomb.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(AntimatterBombEntityPrefab).GetComponent <Entity>(); break; case Constants.Entities. SandBags.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(SandBagsEntityPrefab).GetComponent <Entity>(); break; // Hub case Constants.Entities.Hub.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(factionIndex == 1 ? Faction1Hub : Faction2Hub).GetComponent <Entity>(); break; // Ore case Constants.Entities.Ore.ID: FactionEntities[factionIndex, entityUpdate.unitIndex] = GameObject.Instantiate(OreEntityPrefab).GetComponent <Entity>(); break; default: Debug.Log("PLAYER ERROR: NO CASE FOR THAT ENTITY!"); break; } // Manually set indices for requests FactionEntities[factionIndex, entityUpdate.unitIndex].factionID = factionIndex; FactionEntities[factionIndex, entityUpdate.unitIndex].entityID = entityUpdate.unitIndex; } // Route new state to correct unit int correct faction FactionEntities[factionIndex, entityUpdate.unitIndex].UpdateState(entityUpdate); //print("GOT ENTITY UPDATE"); }