Ejemplo n.º 1
0
        public override void UseHotkey(int hotkeyIndex)
        {
            if (hotkeyIndex < 0 || hotkeyIndex >= PlayerCharacterEntity.Hotkeys.Count)
            {
                return;
            }

            CancelBuild();
            buildingItemIndex     = -1;
            CurrentBuildingEntity = null;

            CharacterHotkey hotkey = PlayerCharacterEntity.Hotkeys[hotkeyIndex];
            Skill           skill  = hotkey.GetSkill();

            if (skill != null)
            {
                short skillLevel;
                if (PlayerCharacterEntity.CacheSkills.TryGetValue(skill, out skillLevel))
                {
                    if (skill.CanUse(PlayerCharacterEntity, skillLevel))
                    {
                        PlayerCharacterEntity.StopMove();
                        queueSkill = skill;
                    }
                }
            }
            Item item = hotkey.GetItem();

            if (item != null)
            {
                int itemIndex = PlayerCharacterEntity.IndexOfNonEquipItem(item.DataId);
                if (itemIndex >= 0)
                {
                    if (item.IsEquipment())
                    {
                        PlayerCharacterEntity.RequestEquipItem((short)itemIndex);
                    }
                    else if (item.IsPotion() || item.IsPet())
                    {
                        PlayerCharacterEntity.RequestUseItem((short)itemIndex);
                    }
                    else if (item.IsBuilding())
                    {
                        PlayerCharacterEntity.StopMove();
                        buildingItemIndex     = itemIndex;
                        CurrentBuildingEntity = Instantiate(item.buildingEntity);
                        CurrentBuildingEntity.SetupAsBuildMode();
                        CurrentBuildingEntity.CacheTransform.parent = null;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void UseHotkey(int hotkeyIndex)
        {
            if (hotkeyIndex < 0 || hotkeyIndex >= PlayerCharacterEntity.Hotkeys.Count)
            {
                return;
            }

            CancelBuild();
            buildingItemIndex     = -1;
            CurrentBuildingEntity = null;

            CharacterHotkey hotkey = PlayerCharacterEntity.Hotkeys[hotkeyIndex];
            Skill           skill  = hotkey.GetSkill();

            if (skill != null)
            {
                short skillLevel;
                if (PlayerCharacterEntity.CacheSkills.TryGetValue(skill, out skillLevel))
                {
                    BaseCharacterEntity attackingCharacter;
                    if (TryGetAttackingCharacter(out attackingCharacter))
                    {
                        // If attacking any character, will use skill later
                        queueUsingSkill = new UsingSkillData(null, skill.DataId);
                    }
                    else if (skill.CanUse(PlayerCharacterEntity, skillLevel))
                    {
                        // If not attacking any character, use skill immediately
                        if (skill.IsAttack())
                        {
                            if (IsLockTarget())
                            {
                                // If attacking any character, will use skill later
                                queueUsingSkill = new UsingSkillData(null, skill.DataId);
                                if (SelectedEntity != null && SelectedEntity is BaseCharacterEntity)
                                {
                                    // Attacking selected target
                                    PlayerCharacterEntity.SetTargetEntity(SelectedEntity);
                                }
                                else
                                {
                                    // Attacking nearest target
                                    BaseCharacterEntity nearestTarget = PlayerCharacterEntity.FindNearestAliveCharacter <BaseCharacterEntity>(PlayerCharacterEntity.GetSkillAttackDistance(skill, isLeftHandAttacking) + lockAttackTargetDistance, false, true, false);
                                    if (nearestTarget != null)
                                    {
                                        PlayerCharacterEntity.SetTargetEntity(nearestTarget);
                                    }
                                }
                            }
                            else
                            {
                                // Not lock target, use it immediately
                                destination = null;
                                PlayerCharacterEntity.StopMove();
                                PlayerCharacterEntity.RequestUseSkill(skill.DataId, isLeftHandAttacking);
                                isLeftHandAttacking = !isLeftHandAttacking;
                            }
                        }
                        else
                        {
                            // This is not attack skill, use it immediately
                            destination = null;
                            PlayerCharacterEntity.StopMove();
                            PlayerCharacterEntity.RequestUseSkill(skill.DataId, isLeftHandAttacking);
                        }
                    }
                }
            }
            Item item = hotkey.GetItem();

            if (item != null)
            {
                int itemIndex = PlayerCharacterEntity.IndexOfNonEquipItem(item.DataId);
                if (itemIndex >= 0)
                {
                    if (item.IsEquipment())
                    {
                        RequestEquipItem((short)itemIndex);
                    }
                    else if (item.IsPotion() || item.IsPet())
                    {
                        RequestUseItem((short)itemIndex);
                    }
                    else if (item.IsBuilding())
                    {
                        destination = null;
                        PlayerCharacterEntity.StopMove();
                        buildingItemIndex     = itemIndex;
                        CurrentBuildingEntity = Instantiate(item.buildingEntity);
                        CurrentBuildingEntity.SetupAsBuildMode();
                        CurrentBuildingEntity.CacheTransform.parent = null;
                        FindAndSetBuildingAreaFromCharacterDirection();
                    }
                }
            }
        }