コード例 #1
0
        public void SetAbility(AbilityType abilityType)
        {
            if (Engine.Player == null)
            {
                return;
            }

            switch (abilityType)
            {
            case AbilityType.Primary when !IsPrimaryEnabled:
                Enabled = AbilityType.Primary;
                break;

            case AbilityType.Secondary when !IsSecondaryEnabled:
                Enabled = AbilityType.Secondary;
                break;

            default:
                Enabled = AbilityType.None;
                break;
            }

            int twoHandSerial = Engine.Player.GetLayer(Layer.TwoHanded);

            Item twoHandItem = Engine.Items.GetItem(twoHandSerial);

            if (twoHandItem != null)
            {
                WeaponData wd =
                    (_weaponData ?? throw new InvalidOperationException()).FirstOrDefault(d =>
                                                                                          d.Graphic == twoHandItem.ID);

                if (wd != null)
                {
                    UOC.SetWeaponAbility(abilityType == AbilityType.Primary ? wd.Primary : wd.Secondary);
                    return;
                }
            }

            int oneHandSerial = Engine.Player.GetLayer(Layer.OneHanded);

            Item oneHandItem = Engine.Items.GetItem(oneHandSerial);

            if (oneHandItem != null)
            {
                WeaponData wd =
                    (_weaponData ?? throw new InvalidOperationException()).FirstOrDefault(d =>
                                                                                          d.Graphic == oneHandItem.ID);

                if (wd != null)
                {
                    UOC.SetWeaponAbility(abilityType == AbilityType.Primary ? wd.Primary : wd.Secondary);
                    return;
                }
            }

            // Fists etc
            UOC.SetWeaponAbility(abilityType == AbilityType.Primary ? 11 : 5);
        }