Esempio n. 1
0
    public void AddItem(ItemClass itemType, Vector3 addPosition, string itemInfoFromServer)
    {
        if (itemInfoFromServer == null)
        {
            // Instantiate unit and instantiate starting cooldown and player
            ItemClass newItem = Instantiate(itemType, new Vector3(addPosition.x, TileArray[(int)addPosition.x, (int)addPosition.z].tile_elevation, addPosition.z), Quaternion.identity);

            // Create entityID
            newItem.entityID = GameObjectID.CreateID("ITEM");

            // Send item to firebase
            if (GAME_MODE == "multiplayer")
            {
                turnManager.SendMoveToFirebase(PLAYER_TEAM + "|IADD|" + newItem.entityID + "|" + newItem.entityName + "|" + addPosition.x + "|" + addPosition.z);
            }
        }
        else
        {
            string[] aData = itemInfoFromServer.Split('|');

            if (Convert.ToInt32(aData[0]) != PLAYER_TEAM)
            {
                string itemName = aData[3].Replace("(Clone)", "");

                // Determine item type
                switch (itemName)
                {
                case "Health Potion":
                    itemType = itemHealthPotion;
                    break;

                case "Mana Potion":
                    itemType = itemManaPotion;
                    break;
                }

                int xCoord = Convert.ToInt32(aData[4]);
                int zCoord = Convert.ToInt32(aData[5]);

                addPosition.x = xCoord;
                addPosition.y = TileArray[xCoord, zCoord].tile_elevation;
                addPosition.z = zCoord;

                // Instantiate item and set entityID (... might be unnecessary step)
                ItemClass newItem = Instantiate(itemType, addPosition, Quaternion.identity);

                newItem.entityID = aData[2];

                // Set TURN_PROCESSING to false since AdvanceTurn() is not called here
                turnManager.SetTurnProcessingFalse("AddItem from Firebase");
            }
        }
    }
Esempio n. 2
0
    // Unit functions
    public void AddUnit(UnitClass unitType, Vector3 addPosition, int unitTeam, bool is_ai, string unitInfoFromServer)
    {
        if (unitInfoFromServer == null)
        {
            // Instantiate unit and instantiate starting cooldown and player
            UnitClass newUnit = Instantiate(unitType, new Vector3(addPosition.x, TileArray[(int)addPosition.x, (int)addPosition.z].tile_elevation, addPosition.z), Quaternion.identity);

            // Point unit at center of map...
            newUnit.transform.LookAt(new Vector3(5, newUnit.transform.position.y, 5));

            newUnit.playerName = PLAYER_NAME;
            newUnit.playerTeam = unitTeam;

            // Create unitID and Cooldown
            newUnit.entityID = GameObjectID.CreateID(PLAYER_NAME);
            int initRandomCooldown = StaticRandom.GetRandom(1, newUnit.unitCooldownMax);
            newUnit.unitCooldown = initRandomCooldown;

            if (is_ai)
            {
                newUnit.IS_AI = true;
            }


            // Add to local unitList
            unitList.Add(newUnit);

            // Add to unit firebase unit list
            if (GAME_MODE == "multiplayer")
            {
                string unitJson = JsonUtility.ToJson(newUnit);
                gameDatabaseReference.Child("units").Push().SetRawJsonValueAsync(unitJson);
                turnManager.SendMoveToFirebase(PLAYER_TEAM + "|CADD|" + newUnit.playerName + "|" + newUnit.entityID + "|" + newUnit.entityName + "|" + addPosition.x + "|" + addPosition.z + "|" + newUnit.unitCooldown);
            }
        }
        else
        {
            string[] aData = unitInfoFromServer.Split('|');

            if (Convert.ToInt32(aData[0]) != PLAYER_TEAM)
            {
                string unitName = aData[4].Replace("(Clone)", "");

                // Determine unit type
                switch (unitName)
                {
                case "Cloud":
                    unitType = unitCloud;
                    break;

                case "Black Rook":
                    unitType = unitBlackRook;
                    break;

                case "Medic":
                    unitType = unitMedic;
                    break;

                case "Insektobot":
                    unitType = unitInsektobot;
                    break;

                case "Bad Robut":
                    unitType = unitBadRobut;
                    break;

                case "Sun Man":
                    unitType = unitSunMan;
                    break;
                }

                int xCoord = Convert.ToInt32(aData[5]);
                int zCoord = Convert.ToInt32(aData[6]);

                addPosition.x = xCoord;
                addPosition.y = TileArray[xCoord, zCoord].tile_elevation;
                addPosition.z = zCoord;

                // Instantiate unit and instantiate starting cooldown and player
                UnitClass newUnit = Instantiate(unitType, addPosition, Quaternion.identity);

                newUnit.playerName   = aData[2];
                newUnit.playerTeam   = Convert.ToInt32(aData[0]);
                newUnit.entityID     = aData[3];
                newUnit.unitCooldown = Convert.ToInt32(aData[7]);

                // Look at center of map...
                newUnit.transform.LookAt(new Vector3(5, transform.position.y, 5));

                // Add to local unitList
                unitList.Add(newUnit);
            }
        }
    }