Exemple #1
0
        void FillAmmo(PlayerSession player)
        {
            if (!player.IsLoaded || !player.Player.isConnected)
            {
                return;
            }

            NetworkEntityComponentBase netEntity = player.WorldPlayerEntity.GetComponent <NetworkEntityComponentBase>();

            if (netEntity == null)
            {
                return;
            }

            EquippedHandlerBase equippedHandler = netEntity.GetComponent <EquippedHandlerBase>();

            if (equippedHandler == null)
            {
                return;
            }

            EquippedHandlerServer equippedHandlerServer = equippedHandler as EquippedHandlerServer;

            if (equippedHandlerServer == null)
            {
                return;
            }

            ItemInstance equippedItem = equippedHandler.GetEquippedItem();

            if (equippedItem == null)
            {
                return;
            }

            GunItem gunItem = equippedItem.Item as GunItem;
            BowItem bowItem = equippedItem.Item as BowItem;

            if ((bowItem != null || gunItem != null) && equippedHandlerServer != null)
            {
                if (gunItem != null)
                {
                    AutomaticGunItem     aGunItem      = gunItem as AutomaticGunItem;
                    GunItemEquippedState gunEquipState = gunItem.EquippedState(equippedHandler);

                    equippedItem.AuxData = Convert.ToByte(gunItem.GetClipSize());
                    equippedHandlerServer.AuxSync();
                }
                else
                {
                    PlayerInventory inventory = player.WorldPlayerEntity.GetComponent <PlayerInventory>();

                    if (!inventory.HasItem(bowItem.GetAmmoType().ItemId, 1))
                    {
                        GiveItem(player, bowItem.GetAmmoType(), 1);
                    }
                }
            }
        }
        ////////////////////////////////////////
        ///     Ammo Related
        ////////////////////////////////////////

        /*void OnWeaponFired(IItem item, EquippedHandlerBase handler)
         * {
         * }*/

        void LoadAmmo(PlayerSession player)
        {
            if (!player.IsLoaded)
            {
                return;
            }

            NetworkEntityComponentBase netEntity = player.WorldPlayerEntity.GetComponent <NetworkEntityComponentBase>();

            if (netEntity == null)
            {
                return;
            }

            EquippedHandlerBase equippedHandler = netEntity.GetComponent <EquippedHandlerBase>();

            if (equippedHandler == null)
            {
                return;
            }

            EquippedHandlerServer equippedHandlerServer = equippedHandler as EquippedHandlerServer;

            if (equippedHandlerServer == null)
            {
                return;
            }

            ItemInstance equippedItem = equippedHandler.GetEquippedItem();

            if (equippedItem == null)
            {
                return;
            }

            GunItem gunItem = equippedItem.Item as GunItem;
            BowItem bowItem = equippedItem.Item as BowItem;

            //PrintWarning($"Item: {equippedItem.Item.GetNameKey().Split('/').Last()}");
            //PrintWarning($"Is Gun: {!(gunItem == null)}");

            if ((bowItem != null || gunItem != null) && equippedHandlerServer != null)
            {
                if (gunItem != null)
                {
                    AutomaticGunItem     aGunItem      = gunItem as AutomaticGunItem;
                    GunItemEquippedState gunEquipState = gunItem.EquippedState(equippedHandler);

                    //PrintWarning($"Is Automatic: {!(aGunItem == null)}");
                    //PrintWarning($"Clip Size: {gunItem.GetClipSize().ToString()}");
                    //PrintWarning($"Ammo Count: {equippedItem.AuxData.ToString()}");

                    //if (equippedItem.AuxData <= 1)
                    //{
                    equippedItem.AuxData = Convert.ToByte(gunItem.GetClipSize());
                    equippedHandlerServer.AuxSync();
                    //}
                }
                else
                {
                    PlayerInventory inventory = player.WorldPlayerEntity.GetComponent <PlayerInventory>();

                    //PrintWarning($"Has Ammo: {inventory.HasItem(bowItem.GetAmmoType().ItemId, 1)}");

                    if (!inventory.HasItem(bowItem.GetAmmoType().ItemId, 1))
                    {
                        GiveItem(player, bowItem.GetAmmoType(), 1);
                    }
                }
            }
        }