Beispiel #1
0
 private void TransferFunds(InventoryItem item, InventoryItemState oldState, InventoryItemState newState)
 {
     if (newState == InventoryItemState.Available && oldState != InventoryItemState.Available)
     {
         GlobalModel.Gold.Value += item.Price.Gold / 2;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Sets the collectible count to the given value.
        /// </summary>
        /// <param name="collectibleCount"></param>
        /// <param name="commit">If true, commit the results to storage.</param>
        private void Set(CollectibleCount collectibleCount, bool commit)
        {
            var item = new InventoryItemState
            {
                CollectibleId = collectibleCount.CollectibleId,
                Count         = collectibleCount.Count,
                CollectTime   = ClockManager.Instance.Now
            };

            if (item.Limit.HasValue)
            {
                item.Count = Math.Min(item.Count, item.Limit.Value);
            }

            m_inventoryItems[collectibleCount.CollectibleId] = item;

            if (Updated != null)
            {
                Updated(this, EventArgs.Empty);
            }

            if (commit)
            {
                Save();
            }
        }
Beispiel #3
0
 public InventoryItemStateChangedEventArgs(
     Guid itemId = default(Guid),
     InventoryItemState oldState = InventoryItemState.Other,
     InventoryItemState newState = InventoryItemState.Other)
 {
     this.ItemId   = itemId;
     this.OldState = oldState;
     this.NewState = newState;
 }
 public void OnItemStateChanged(Guid itemId, InventoryItemState oldState, InventoryItemState newState)
 {
     if (ItemStateChanged != null)
         ItemStateChanged(this, new InventoryItemStateChangedEventArgs
      		{
             ItemId = itemId,
             OldState = oldState,
             NewState = newState
         });
 }
Beispiel #5
0
        public static IEnumerable <IInventoryItemState> ToInventoryItemStateCollection(IEnumerable <InventoryItemId> ids)
        {
            var states = new List <InventoryItemState>();

            foreach (var id in ids)
            {
                var s = new InventoryItemState();
                s.InventoryItemId = id;
                states.Add(s);
            }
            return(states);
        }
Beispiel #6
0
        private void TriggerCollectionUpdatedEvent(InventoryItemState state)
        {
            switch (state)
            {
            case InventoryItemState.Purchased:
                OnPurchasedItemsUpdated();
                break;

            case InventoryItemState.Equipped:
                OnEquippedItemsUpdated();
                break;
            }
        }
Beispiel #7
0
        private ICollection <InventoryItem> GetInventoryItemsCollection(InventoryItemState state)
        {
            switch (state)
            {
            case InventoryItemState.Available: return(GlobalModel.Inventory.AvailableItems);

            case InventoryItemState.Purchased: return(GlobalModel.Inventory.PurchasedItems);

            case InventoryItemState.Equipped: return(GlobalModel.Inventory.EquippedItems);

            default: return(new List <InventoryItem>());
            }
        }
Beispiel #8
0
        private void Add(string collectibleId, int count, bool commit)
        {
            if (collectibleId == null)
            {
                return;
            }

            InventoryItemState item = null;

            if (!m_inventoryItems.ContainsKey(collectibleId))
            {
                item = new InventoryItemState
                {
                    CollectibleId = collectibleId,
                    Count         = count,
                    CollectTime   = ClockManager.Instance.Now
                };

                m_inventoryItems[collectibleId] = item;
            }
            else
            {
                item = m_inventoryItems[collectibleId];

                item.Count      += count;
                item.CollectTime = ClockManager.Instance.Now;
            }

            if (item.Limit.HasValue)
            {
                item.Count = Math.Min(item.Count, item.Limit.Value);
            }

            var collectible = CollectibleDirectory.Instance.GetItem(collectibleId);

            if (collectible != null && collectible.IsSingleton && item.Count > 1)
            {
                item.Count = 1;
            }

            if (Updated != null)
            {
                Updated(this, EventArgs.Empty);
            }

            if (commit)
            {
                Save();
            }
        }
    public void Purchase()
    {
        InitializeIfNeeded();

        if (this.tcScript.doubleDollars >= doubleDollarCostToPurchase &&
            this.tcScript.diamonds >= diamondCostToPurchase)
        {
            this.tcScript.SubtractDoubleDollars(doubleDollarCostToPurchase);
            this.tcScript.SubtractDiamonds(diamondCostToPurchase);
            this.state = InventoryItemState.INVENTORY_ITEM_STATE_PURCHASED;
            this.level = 1;
            this.UpdateStats();
        }
    }
Beispiel #10
0
        public IInventoryItemState Get(InventoryItemId id, bool nullAllowed)
        {
            IInventoryItemState state = CurrentSession.Get <InventoryItemState> (id);

            if (!nullAllowed && state == null)
            {
                state = new InventoryItemState();
                (state as InventoryItemState).InventoryItemId = id;
            }
            if (ReadOnlyProxyGenerator != null && state != null)
            {
                return(ReadOnlyProxyGenerator.CreateProxy <IInventoryItemState>(state, new Type[] { typeof(ISaveable) }, _readOnlyPropertyNames));
            }
            return(state);
        }
    public void EquipToUnit(UnitDataObject unit)
    {
        InitializeIfNeeded();

        this.equippedByUnit = unit;
        if (this.type == InventoryItemType.INVENTORY_ITEM_TYPE_ARMOR)
        {
            unit.equippedArmor = (Armor)this;
        }
        else if (this.type == InventoryItemType.INVENTORY_ITEM_TYPE_WEAPON)
        {
            unit.equippedWeapon = (Weapon)this;
        }

        this.state = InventoryItemState.INVENTORY_ITEM_STATE_EQUIPPED;
        this.level = 1;
        this.UpdateStats();
    }
    public void Sell()
    {
        InitializeIfNeeded();

        if (this.level >= 3)
        {
            this.tcScript.AddDoubleDollars(Mathf.FloorToInt(SELL_PERCENTAGE * doubleDollarCostToUpgradeToLevel3));
            this.tcScript.AddDiamonds(Mathf.FloorToInt(SELL_PERCENTAGE * diamondCostToUpgradeToLevel3));
        }
        if (this.level >= 2)
        {
            this.tcScript.AddDoubleDollars(Mathf.FloorToInt(SELL_PERCENTAGE * doubleDollarCostToUpgradeToLevel2));
            this.tcScript.AddDiamonds(Mathf.FloorToInt(SELL_PERCENTAGE * diamondCostToUpgradeToLevel2));
        }
        if (this.level >= 1)
        {
            this.tcScript.AddDoubleDollars(Mathf.FloorToInt(SELL_PERCENTAGE * doubleDollarCostToPurchase));
            this.tcScript.AddDiamonds(Mathf.FloorToInt(SELL_PERCENTAGE * diamondCostToPurchase));
        }
        this.state = InventoryItemState.INVENTORY_ITEM_STATE_NOT_PURCHASED;
    }
Beispiel #13
0
        internal void SetLimits(InventoryCollectibleLimit limits)
        {
            if (limits.CollectibleCounts != null)
            {
                foreach (var limit in limits.CollectibleCounts)
                {
                    InventoryItemState item;

                    if (!m_inventoryItems.TryGetValue(limit.CollectibleId, out item))
                    {
                        item = new InventoryItemState
                        {
                            CollectibleId = limit.CollectibleId,
                            Limit         = int.MaxValue
                        };

                        m_inventoryItems[item.CollectibleId] = item;
                    }

                    item.Limit = MathHelper.ApplyNumericalOperator(limits.Operator, item.Limit.GetValueOrDefault(), limit.Count);
                }
            }
        }
 public InventoryItemUpgradedEventArgs(Guid id, InventoryItemState state = InventoryItemState.Other)
 {
     this.ItemId    = id;
     this.ItemState = state;
 }
 private void OnItemUpgraded(Guid id, InventoryItemState state)
 {
     if (ItemUpgraded != null) ItemUpgraded(this, new InventoryItemUpgradedEventArgs(id, state));
 }