public StatTable(StatTable other)
        {
            id = nextId++;

            // Base values must be copied
            BaseValues = new StatMap(other.BaseValues);

            // Don't need to copy these directly, as changing level will propagate changes
            LeveledValues  = new StatMap();
            ModifiedValues = new StatMap();

            // Progressions, modifiers, dependants must be copied
            Progressions = new StatMap(other.Progressions);
            Dependants   = new StatDependantMap(other.Dependants);

            // Modifiers need extra care, as they need to refer to other objects
            Modifiers = new Dictionary <string, ModifierMap>();
            foreach (KeyValuePair <string, ModifierMap> modMap in other.Modifiers)
            {
                foreach (KeyValuePair <ModifierType, HashSet <StatModifier> > modSet in modMap.Value)
                {
                    foreach (StatModifier mod in modSet.Value)
                    {
                        AddModifier(new StatModifier(mod, this));
                    }
                }
            }

            // Using property fills out leveled and modified values
            Level = other.Level;
        }
        public Item UnequipItem(SlotType slot, StatTable heroStats)
        {
            Item removedItem = null;

            if (!Items.TryGetValue(slot, out removedItem) ||
                removedItem is null || removedItem.Name == Item.EmptyItemText)
            {
                return(null);
            }

            // DON'T actually remove - breaks bindings
            Items[slot] = new Item();

            // Handle two-handed weapons
            if (removedItem.slot == SlotType.BothHands)
            {
                if (slot == SlotType.MainHand)
                {
                    Items[SlotType.OffHand] = new Item();
                }
                else if (slot == SlotType.OffHand)
                {
                    Items[SlotType.MainHand] = new Item();
                }
            }

            RemoveItemModsFromHeroStats(removedItem, heroStats);

            return(removedItem);
        }
 public GameObject(GameObject other)
 {
     Name        = other.Name;
     Archetype   = other.Archetype;
     Description = other.Description;
     stats       = new StatTable(other.stats);
 }
        //------------------------------------------------------------------------------
        // Private Functions:
        //------------------------------------------------------------------------------

        private void AddItemModsToHeroStats(Item itemToEquip, StatTable heroStats)
        {
            // Add stats from item to hero stat mods
            foreach (KeyValuePair <string, float> moddedStat in itemToEquip.Stats.ModifiedValues)
            {
                heroStats.AddModifier(new StatModifier(moddedStat.Key,
                                                       null, ModifierType.Additive, moddedStat.Value, itemToEquip));
            }
        }
 private void RemoveItemModsFromHeroStats(Item unequipped, StatTable heroStats)
 {
     // Remove stats from item from hero stat mods
     foreach (KeyValuePair <string, float> moddedStat in unequipped.Stats.ModifiedValues)
     {
         heroStats.RemoveModifier(new StatModifier(moddedStat.Key,
                                                   null, ModifierType.Additive, moddedStat.Value, unequipped));
     }
 }
Example #6
0
 public StatModifier(StatModifier other, StatTable newTable)
 {
     statName        = other.statName;
     modSourceStat   = other.modSourceStat;
     type            = other.type;
     ModValue        = other.ModValue;
     ModSourceObject = other.ModSourceObject;
     if (ModSourceObject != null)
     {
         modSourceTable = newTable;
     }
 }
        public void EquipItem(Item item, StatTable heroStats)
        {
            // Handle two-handed weapons
            if (item.slot == SlotType.BothHands)
            {
                Items[SlotType.MainHand] = item;
                Items[SlotType.OffHand]  = item;
            }
            // Handle other slots
            else
            {
                Items[item.slot] = item;
            }

            AddItemModsToHeroStats(item, heroStats);
        }
        //------------------------------------------------------------------------------
        // Public Functions:
        //------------------------------------------------------------------------------

        public GameObject(string name_, string archetype_ = "")
        {
            Name      = name_;
            Archetype = archetype_;
            stats     = new StatTable();
        }