コード例 #1
0
        public bool IsEnough(NeedItems needItems)
        {
            foreach (var n in needItems.Elements)
            {
                if (!this.IsEnough(n.MasterDataRecord, n.Amount))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        public void Consume(NeedItems needItems, List <InstanceWeapon> instanceWeapons, int money)
        {
            foreach (var element in needItems.Elements)
            {
                var record = element.MasterDataRecord;
                if (record is AccessoryRecord)
                {
                    var possessionCount = this.GetPossessionCount(record);
                    Assert.AreNotEqual(possessionCount, 0, "アクセサリーを所持していないのに消費しようとしました");
                    var equippedAccessoryIndex       = -1;
                    var equippedAccessoryRecordIndex = -1;
                    var equippedAccessories          = this.owner.StatusController.EquippedAccessories;
                    for (var i = 0; i < equippedAccessories.Count; i++)
                    {
                        if (equippedAccessories[i] < 0)
                        {
                            continue;
                        }
                        if (this.accessories[equippedAccessories[i]] == record)
                        {
                            equippedAccessoryIndex       = i;
                            equippedAccessoryRecordIndex = equippedAccessories[i];
                            break;
                        }
                    }

                    if (possessionCount == 1)
                    {
                        // 装備中のアクセサリーだった場合は外す
                        if (equippedAccessoryIndex != -1)
                        {
                            this.owner.StatusController.ChangeEquippedAccessory(equippedAccessoryIndex, -1);
                        }

                        this.accessories.Remove(record as AccessoryRecord);
                        if (equippedAccessoryRecordIndex != -1)
                        {
                            this.owner.StatusController.DecreaseEquippedAccessoryIndex(equippedAccessoryRecordIndex);
                        }
                    }
                    else
                    {
                        for (var i = 0; i < this.accessories.Count; i++)
                        {
                            // 装備していないアクセサリーを探して消費する
                            if (this.accessories[i] == record && i != equippedAccessoryRecordIndex)
                            {
                                this.accessories.RemoveAt(i);
                                this.owner.StatusController.DecreaseEquippedAccessoryIndex(i);
                                break;
                            }
                        }
                    }
                }
                else if (record is MaterialRecord)
                {
                    this.materials[(record as MaterialRecord)].Add(-element.Amount);
                }
                else if (record is WeaponRecord)
                {
                    // 何もしないけど次のAssertで引っかからないようにあえて書いておく
                }
                else
                {
                    Assert.IsTrue(false, $"{record.GetType()}は未定義の動作です");
                }
            }

            if (instanceWeapons != null)
            {
                foreach (var instanceWeapon in instanceWeapons)
                {
                    this.weapons.Remove(instanceWeapon);

                    // 装備中の武器だった場合は何も装備しなくする
                    var equippedWeaponIndex = this.owner.StatusController.EquippedWeapons.FindIndex(m => m.InstanceWeapon == instanceWeapon);
                    if (equippedWeaponIndex != -1)
                    {
                        this.owner.StatusController.RemoveEquippedWeapon(equippedWeaponIndex);
                    }
                }
            }

            this.AddMoney(-money);
        }