Beispiel #1
0
    private void _syncInventory(String info)
    {
        // No need to do on server as server already perform it
        if (!GetTree().IsNetworkServer())
        {
            String[] splitInfo = info.Split(",");
            int      infoIndex = 0;

            TeamMapAI teamMapAI = _gameWorld.GetTeamMapAIs()[int.Parse(splitInfo[infoIndex])];
            infoIndex++;

            Agent agent = teamMapAI.GetUnit(splitInfo[infoIndex]);
            infoIndex++;

            if (agent != null && IsInstanceValid(agent))
            {
                Inventory inventory = agent.GetInventory();

                if (inventory != null && IsInstanceValid(inventory))
                {
                    inventory.SyncInventoryState(splitInfo[infoIndex], _inventoryDatabase);
                }
            }
        }
    }
Beispiel #2
0
    private void _serverEquipItem(String info)
    {
        int       inventoryItemIndex = int.Parse(info.Split(";")[0]);
        TeamMapAI teamMapAI          = _gameWorld.GetTeamMapAIs()[int.Parse(info.Split(";")[1])];
        Agent     agent = teamMapAI.GetUnit(info.Split(";")[2]);

        Weapon.WeaponOrder weaponOrder = (Weapon.WeaponOrder) int.Parse(info.Split(";")[3]);
        int weaponIndex = int.Parse(info.Split(";")[4]);

        if (agent != null && IsInstanceValid(agent))
        {
            Inventory inventory = agent.GetInventory();

            // Inventory is not null
            if (inventory != null && IsInstanceValid(inventory) && inventory.GetItem(inventoryItemIndex) != null)
            {
                // It is not in used and is equiptable
                if (!inventory.IsItemIndexInUsed(inventoryItemIndex) && inventory.GetItem(inventoryItemIndex).CurrentItemType == ItemResource.ItemType.EQUIPABLE)
                {
                    // Server local directly process
                    inventory.EquipItem(inventoryItemIndex, weaponOrder, weaponIndex);
                }

                // Sync the client no matter if is passing (if not passing, it may indicate cliet is out of sync with server inventory so need to sync)
                if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer())
                {
                    SyncInventory(-1, agent);
                }
            }
        }
    }
Beispiel #3
0
    private void _serverAddItem(String info)
    {
        String[] splitInfo = info.Split(";");
        int      infoIndex = 0;

        ItemResource itemResource = _inventoryDatabase.GetItemByID(splitInfo[infoIndex]);

        infoIndex++;

        TeamMapAI teamMapAI = _gameWorld.GetTeamMapAIs()[int.Parse(splitInfo[infoIndex])];

        infoIndex++;

        Agent agent = teamMapAI.GetUnit(splitInfo[infoIndex]);

        infoIndex++;

        if (agent != null && IsInstanceValid(agent) && itemResource != null && IsInstanceValid(itemResource))
        {
            Inventory inventory = agent.GetInventory();

            if (inventory != null && IsInstanceValid(inventory))
            {
                inventory.AddItem(itemResource);

                // Sync the client no matter if is passing (if not passing, it may indicate cliet is out of sync with server inventory so need to sync)
                if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer())
                {
                    SyncInventory(-1, agent);
                }
            }
        }
    }
Beispiel #4
0
    private void _serverRemoveItem(String info)
    {
        String[] splitInfo = info.Split(";");
        int      infoIndex = 0;

        int inventoryIndex = int.Parse(splitInfo[infoIndex]);

        infoIndex++;

        TeamMapAI teamMapAI = _gameWorld.GetTeamMapAIs()[int.Parse(splitInfo[infoIndex])];

        infoIndex++;

        Agent agent = teamMapAI.GetUnit(splitInfo[infoIndex]);

        infoIndex++;

        int dropItem = int.Parse(splitInfo[infoIndex]);

        infoIndex++;

        if (agent != null && IsInstanceValid(agent))
        {
            Inventory inventory = agent.GetInventory();

            if (inventory != null && IsInstanceValid(inventory))
            {
                if (inventory.GetItem(inventoryIndex) != null && !inventory.IsItemIndexInUsed(inventoryIndex))
                {
                    ItemResource itemResource = inventory.GetItem(inventoryIndex);
                    inventory.RemoveItem(inventoryIndex);

                    // Will drop item even if local client not able to remove it, as to sync up state with other servers
                    if (dropItem == 1)
                    {
                        Vector2 itemPosition = agent.GlobalPosition + new Vector2(200f, 200f);

                        _createPickUp(itemResource, itemPosition);

                        if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer())
                        {
                            String dropItemInfo = itemResource.ItemID + ";" + itemPosition.x + ";" + itemPosition.y + ";";
                            Rpc(nameof(_clientCreatePickUp), dropItemInfo);
                        }
                    }
                }

                // Sync the client no matter if is passing (if not passing, it may indicate cliet is out of sync with server inventory so need to sync)
                if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer())
                {
                    SyncInventory(-1, agent);
                }
            }
        }
    }
Beispiel #5
0
    private void _serverUseItem(String info)
    {
        String[] splitInfo = info.Split(";");
        int      infoIndex = 0;

        int inventoryIndex = int.Parse(splitInfo[infoIndex]);

        infoIndex++;

        TeamMapAI teamMapAI = _gameWorld.GetTeamMapAIs()[int.Parse(splitInfo[infoIndex])];

        infoIndex++;

        Agent agent = teamMapAI.GetUnit(splitInfo[infoIndex]);

        infoIndex++;


        if (agent != null && IsInstanceValid(agent))
        {
            Inventory inventory = agent.GetInventory();

            if (inventory != null && IsInstanceValid(inventory))
            {
                if (inventory.GetItem(inventoryIndex) != null && !inventory.IsItemIndexInUsed(inventoryIndex))
                {
                    ItemResource itemResource = inventory.GetItem(inventoryIndex);

                    inventory.RemoveItem(inventoryIndex);
                    if (itemResource.ItemID == "SYC-010")
                    {
                        agent.Heal(agent.MaxHealth);
                    }
                }

                // Sync the client no matter if is passing (if not passing, it may indicate cliet is out of sync with server inventory so need to sync)
                if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer())
                {
                    SyncInventory(-1, agent);
                }
            }
        }
    }
Beispiel #6
0
    private void _serverPurchaseItem(String info)
    {
        String[] splitInfo = info.Split(";");
        int      infoIndex = 0;

        ItemResource itemResource = _inventoryDatabase.GetItemByID(splitInfo[infoIndex]);

        infoIndex++;

        TeamMapAI teamMapAI = _gameWorld.GetTeamMapAIs()[int.Parse(splitInfo[infoIndex])];

        infoIndex++;

        Agent agent = teamMapAI.GetUnit(splitInfo[infoIndex]);

        infoIndex++;

        if (agent != null && IsInstanceValid(agent))
        {
            Inventory inventory = agent.GetInventory();

            // No need to sync cost as cost will sync by team AI system
            if (inventory != null && IsInstanceValid(inventory) && itemResource != null && IsInstanceValid(itemResource))
            {
                if (inventory.GetAvailableCapacity() > 0 && teamMapAI.ChargeAmount(itemResource.Price))
                {
                    inventory.AddItem(itemResource);
                }

                // Sync the client no matter if is passing the lastcheck
                // If not passing, as long as the agent still exit it may indicate cliet is out of sync with server inventory so need to sync
                if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer())
                {
                    SyncInventory(-1, agent);
                }
            }
        }
    }
Beispiel #7
0
    private void _serverUnequipItem(String info)
    {
        String[] splitInfo = info.Split(";");
        int      infoIndex = 0;

        TeamMapAI teamMapAI = _gameWorld.GetTeamMapAIs()[int.Parse(splitInfo[infoIndex])];

        infoIndex++;

        Agent agent = teamMapAI.GetUnit(splitInfo[infoIndex]);

        infoIndex++;

        Weapon.WeaponOrder weaponOrder = (Weapon.WeaponOrder) int.Parse(splitInfo[infoIndex]);
        infoIndex++;

        int weaponIndex = int.Parse(splitInfo[infoIndex]);

        infoIndex++;

        if (agent != null && IsInstanceValid(agent))
        {
            Inventory inventory = agent.GetInventory();
            if (inventory != null && IsInstanceValid(inventory))
            {
                if (agent.GetWeapons(weaponOrder)[weaponIndex] != null)
                {
                    inventory.UnequipItem(weaponOrder, weaponIndex);
                }
                // Sync the client no matter if is passing (if not passing, it may indicate cliet is out of sync with server inventory so need to sync)
                if (GetTree().NetworkPeer != null && GetTree().IsNetworkServer())
                {
                    SyncInventory(-1, agent);
                }
            }
        }
    }