Exemplo n.º 1
0
        protected void UseItem(string id, Vector3?aimPosition)
        {
            InventoryType inventoryType;
            int           itemIndex;
            byte          equipWeaponSet;
            CharacterItem characterItem;

            if (PlayerCharacterEntity.IsEquipped(
                    id,
                    out inventoryType,
                    out itemIndex,
                    out equipWeaponSet,
                    out characterItem))
            {
                PlayerCharacterEntity.RequestUnEquipItem(inventoryType, (short)itemIndex, equipWeaponSet);
                return;
            }

            if (itemIndex < 0)
            {
                return;
            }

            BaseItem item = characterItem.GetItem();

            if (item == null)
            {
                return;
            }

            if (item.IsEquipment())
            {
                PlayerCharacterEntity.RequestEquipItem((short)itemIndex);
            }
            else if (item.IsSkill())
            {
                bool isAttackSkill = (item as ISkillItem).UsingSkill.IsAttack();
                if (!aimPosition.HasValue)
                {
                    if (PlayerCharacterEntity.RequestUseSkillItem((short)itemIndex, isLeftHandAttacking) && isAttackSkill)
                    {
                        // Requested to use attack skill then change attacking hand
                        isLeftHandAttacking = !isLeftHandAttacking;
                    }
                }
                else
                {
                    if (PlayerCharacterEntity.RequestUseSkillItem((short)itemIndex, isLeftHandAttacking, aimPosition.Value) && isAttackSkill)
                    {
                        // Requested to use attack skill then change attacking hand
                        isLeftHandAttacking = !isLeftHandAttacking;
                    }
                }
            }
            else if (item.IsBuilding())
            {
                buildingItemIndex = itemIndex;
                ShowConstructBuildingDialog();
            }
            else if (item.IsUsable())
            {
                PlayerCharacterEntity.RequestUseItem((short)itemIndex);
            }
        }
Exemplo n.º 2
0
        protected void UseItem(string id, AimPosition aimPosition)
        {
            int      itemIndex;
            BaseItem item;
            int      dataId = BaseGameData.MakeDataId(id);

            if (GameInstance.Items.ContainsKey(dataId))
            {
                item      = GameInstance.Items[dataId];
                itemIndex = OwningCharacter.IndexOfNonEquipItem(dataId);
            }
            else
            {
                InventoryType inventoryType;
                byte          equipWeaponSet;
                CharacterItem characterItem;
                if (PlayerCharacterEntity.IsEquipped(
                        id,
                        out inventoryType,
                        out itemIndex,
                        out equipWeaponSet,
                        out characterItem))
                {
                    GameInstance.ClientInventoryHandlers.RequestUnEquipItem(
                        inventoryType,
                        (short)itemIndex,
                        equipWeaponSet,
                        -1,
                        ClientInventoryActions.ResponseUnEquipArmor,
                        ClientInventoryActions.ResponseUnEquipWeapon);
                    return;
                }
                item = characterItem.GetItem();
            }

            if (itemIndex < 0)
            {
                return;
            }

            if (item == null)
            {
                return;
            }

            if (item.IsEquipment())
            {
                GameInstance.ClientInventoryHandlers.RequestEquipItem(
                    PlayerCharacterEntity,
                    (short)itemIndex,
                    ClientInventoryActions.ResponseEquipArmor,
                    ClientInventoryActions.ResponseEquipWeapon);
            }
            else if (item.IsSkill())
            {
                bool isAttackSkill = (item as ISkillItem).UsingSkill.IsAttack();
                if (PlayerCharacterEntity.UseSkillItem((short)itemIndex, isLeftHandAttacking, SelectedEntityObjectId, aimPosition) && isAttackSkill)
                {
                    isLeftHandAttacking = !isLeftHandAttacking;
                }
            }
            else if (item.IsBuilding())
            {
                buildingItemIndex = itemIndex;
                ShowConstructBuildingDialog();
            }
            else if (item.IsUsable())
            {
                PlayerCharacterEntity.CallServerUseItem((short)itemIndex);
            }
        }