예제 #1
0
        public override void ReadNode(XElement node)
        {
            if (String.IsNullOrEmpty(node.Value))
            {
                ItemInstance = null;
            }
            else
            {
                _itemInstance = new MDRItemInstance();

                var item = CoM.Items.ByID(int.Parse(node.Value));

                if (item == null)
                {
                    Trace.LogWarning("Data Error [Store]: Inventory references an item that doesn't exist.  Item ID {0}.  This item will be ignored.", node.Value);
                    _itemInstance = null;
                    return;
                }

                _itemInstance.Item = item;

                Quantity = ReadAttributeInt(node, "Quantity", 1);
                _itemInstance.RemainingCharges = ReadAttributeInt(node, "Charges", 0);
                _itemInstance.IDLevel          = IdentificationLevel.FromName(ReadAttribute(node, "IDLevel", IdentificationLevel.Full.Name));
                _itemInstance.Cursed           = ReadAttributeBool(node, "Cursed");
                _itemInstance.KnownToBeCursed  = ReadAttributeBool(node, "KnownToBeCursed", false);
            }
        }
예제 #2
0
 /** Attempts to set this slots item to given value, returns true if sucessful.  Items can only be set if the restriction conditions are meet */
 private bool setItem(MDRItemInstance item)
 {
     if (CanAccept(item))
     {
         _itemInstance = item;
         if (Character != null)
         {
             if (item != null)
             {
                 Character.IdentifyItem(item);
             }
         }
         Quantity = 1;
         if (OnAfterSetItem != null)
         {
             OnAfterSetItem(this, item);
         }
         return(true);
     }
     else
     {
         Trace.Log("Can not transfer " + item + " to this slot.");
         return(false);
     }
 }
예제 #3
0
        /** Purchase item, gives to currently selected party memeber. */
        public bool PurchaseItem(MDRItem item)
        {
            MDRCharacter buyer = CoM.Party.Selected;

            if (buyer == null)
            {
                return(false);
            }

            if (CoM.Party.Gold < SellPrice(item))
            {
                return(false);
            }

            // do the transaction
            if (buyer.GiveItem(MDRItemInstance.Create(item)))
            {
                CoM.Party.DebitGold(SellPrice(item), buyer);
                SubtractQuantity(item, 1);
                return(true);
            }
            else
            {
                CoM.PostMessage(buyer + " does not have enough space for " + item);
                return(false);
            }
        }
예제 #4
0
        public MDRItemSlot Create(MDRItemInstance item = null, ItemLocation restriction = ItemLocation.Any, MDRCharacter character = null)
        {
            MDRItemSlot result = new MDRItemSlot();

            result._itemInstance = item;
            result.Restriction   = restriction;
            result.Character     = character;
            return(result);
        }
예제 #5
0
파일: MDRInventory.cs 프로젝트: bsimser/CoM
        /** Adds given item to the correct inventory slot (of the right type).  Returns the slot used if sucessful */
        override public MDRItemSlot ReceiveItem(MDRItemInstance item)
        {
            MDRItemSlot freeSlot = NextFreeSlot();

            if (freeSlot != null)
            {
                freeSlot.ItemInstance = item;
            }
            return(freeSlot);
        }
예제 #6
0
파일: MDRInventory.cs 프로젝트: bsimser/CoM
 /** Makes sure player can equip given item */
 protected bool DoItemCheck(object source, MDRItemInstance item)
 {
     if (item == null)
     {
         return(true);
     }
     if (item.Item == null)
     {
         return(true);
     }
     return(item.CanBeEquipedBy(_character));
 }
예제 #7
0
파일: MDRInventory.cs 프로젝트: bsimser/CoM
        /** Adds given item to inventory.  Returns the slot used if sucessful */
        virtual public MDRItemSlot ReceiveItem(MDRItemInstance item)
        {
            MDRItemSlot freeSlot = NextFreeSlot();

            if (freeSlot != null)
            {
                freeSlot.ItemInstance = item;
            }
            if (OnInventoryChanged != null)
            {
                OnInventoryChanged();
            }
            return(freeSlot);
        }
예제 #8
0
        public MDRItemInstance ReceiveLoot(MDRItem item, MDRMonster sourceMonster, ref MDRCharacter giveToCharacter)
        {
            var instance = MDRItemInstance.Create(item, IdentificationLevel.Auto);

            giveToCharacter = giveToCharacter ?? RandomMember();

            giveToCharacter.GiveItem(instance);

            if (sourceMonster != null)
            {
                CoM.GameStats.RegisterItemFound(giveToCharacter, instance, sourceMonster);
            }

            return(instance);
        }
예제 #9
0
        public static MDRItemInstance Create(MDRItem item, IdentificationLevel idLevel = null)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            MDRItemInstance result = new MDRItemInstance();

            result.Item             = item;
            result.IDLevel          = idLevel ?? IdentificationLevel.Full;
            result.RemainingCharges = Math.Min(item.DefaultCharges, item.Usable ? 1 : 0);
            result.Cursed           = (item.CurseType != ItemCurseType.None);
            result.KnownToBeCursed  = (idLevel == IdentificationLevel.Full) && (result.Cursed);
            return(result);
        }
예제 #10
0
        /** Returns the price this store will buy a given item for */
        public int BuyPrice(MDRItemInstance instance)
        {
            int   quantity       = GetQuantity(instance.Item);
            float quantityFactor = 1f / ((quantity == 0) ? 1 : 1 + (float)Math.Log(quantity));
            float idFactor       = instance.IDLevel.PriceMod;

            if (instance.KnownToBeCursed)
            {
                return(1);
            }
            else
            {
                return((int)(instance.Item.Value / 3 * quantityFactor * idFactor));
            }
        }
예제 #11
0
 /** Returns if this slots can accept the given item */
 public bool CanAccept(MDRItemInstance itemInstance)
 {
     if ((OnBeforeSetItem != null) && (OnBeforeSetItem(this, itemInstance) == false))
     {
         return(false);
     }
     if (itemInstance == null)
     {
         return(true);
     }
     if (Restriction == ItemLocation.Any)
     {
         return(true);
     }
     return(itemInstance.Item.Type.TypeClass.Location == Restriction);
 }
예제 #12
0
파일: MDRInventory.cs 프로젝트: bsimser/CoM
        /** Update players stats when equipment changes */
        protected void DoEquipmentChanged(MDRItemSlot source, MDRItemInstance item)
        {
            // if paired item was two handed then unequip paired item
            if ((item != null) && (source.PairedSlot != null) && (!source.PairedSlot.IsEmpty) && (source.PairedSlot.ItemInstance.Item.Hands == 2))
            {
                _character.UnequipItem(source.PairedSlot);
            }

            // if we are two handed unequip paired item
            if ((source.PairedSlot != null) && !(item == null) && (item.Item.Hands == 2))
            {
                _character.UnequipItem(source.PairedSlot);
            }

            _character.ApplyChanges();
        }