Ejemplo n.º 1
0
 public void Unapply(IEntityStats appliedStatContainer)
 {
     if (this.Applied == true)
     {
         this.Applied = false;
         appliedStatContainer.MarkAsDirty();
     }
 }
Ejemplo n.º 2
0
 public void Apply(IEntityStats appliedStatContainer)
 {
     if (this.Applied == false)
     {
         this.Applied = true;
         appliedStatContainer.ApplyModifier(this);
     }
 }
Ejemplo n.º 3
0
        public IEntity Create(EntityProfile profile)
        {
            IEntityInfo    info      = GenerateEntityInfo(profile.Race, profile.Occupation);
            IEntityStats   stats     = GetStatsPoints(profile.Occupation, profile.Level * 10);
            IEntitySkills  skills    = new EntitySkills();
            IInventory     inventory = new Inventory(20); // smaller inventory for entity
            IEntityAbility abilities = new EntityAbility(GeneralAbilities.All, ItemAbilities.None, EntityAbilities.ModifyInterationAbilities, EffectAbilities.ModifyMagicAbilities, AIAbilities.None);
            Guid           id        = Guid.NewGuid();
            IEntity        entity    = new Entity(id, info, skills, stats, inventory, abilities);

            this.AddOccupation(entity, info.Occupation);

            return(entity);
        }
Ejemplo n.º 4
0
        public void SerializeStats()
        {
            float[]      statValues = new float[] { /*strength*/ 1.0f, /*Stamina*/ 2.0f, /*Wisdom*/ 3.0f, /*Inteligence*/ 4.0f, /*Charisma*/ 5.0f, /*Agility*/ 6.0f, /*Luck*/ 7.0f, /*Speed*/ 8.0f };
            IEntityStats stats      = new EntityStats(statValues);
            IEntityStats statsClone = Serializer.DeepClone(stats);

            Assert.AreEqual(statsClone.Get(StatType.Strength), statsClone.Get(StatType.Strength));
            Assert.AreEqual(statsClone.Get(StatType.Stamina), statsClone.Get(StatType.Stamina));
            Assert.AreEqual(statsClone.Get(StatType.Wisdom), statsClone.Get(StatType.Wisdom));
            Assert.AreEqual(statsClone.Get(StatType.Inteligence), statsClone.Get(StatType.Inteligence));
            Assert.AreEqual(statsClone.Get(StatType.Charisma), statsClone.Get(StatType.Charisma));
            Assert.AreEqual(statsClone.Get(StatType.Constitution), statsClone.Get(StatType.Constitution));
            Assert.AreEqual(statsClone.Get(StatType.Luck), statsClone.Get(StatType.Luck));
            Assert.AreEqual(statsClone.Get(StatType.Dexterity), statsClone.Get(StatType.Dexterity));
        }
Ejemplo n.º 5
0
        public bool DistributePoints(StatType type, IEntityStats stats, float usedSkillPoints = 0)
        {
            bool success = false;

            if (this.UseableSkillPoints <= usedSkillPoints && usedSkillPoints > 0)
            {
                // reduce skill points
                this.skillPoints -= usedSkillPoints;
                // increase base line

                stats.Add(type, usedSkillPoints);

                success = true;
            }
            return(success);
        }
Ejemplo n.º 6
0
        public Entity(Guid id, IEntityInfo info, IEntitySkills skills, IEntityStats stats, IInventory inventory, IEntityAbility abilities)
        {
            Debug.Assert(info != null, "Info cannot be null");
            Debug.Assert(stats != null, "Stats cannot be null");
            Debug.Assert(inventory != null, "inventory cannot be null");
            Debug.Assert(id != null && id != Guid.Empty, "invalid ID");

            this.ID        = id;
            this.Stats     = stats;
            this.Skills    = skills;
            this.Info      = info;
            this.Inventory = inventory;
            this.Abilities = abilities;
            this.MaxHealth = this.Stats.Get(StatType.Constitution) * 10;
            this.Health    = this.MaxHealth;
            this.Effects   = new List <Effect>();
        }
Ejemplo n.º 7
0
        public IItem Get(InventorySlot etype, IEntityStats stats)
        {
            int   index = (int)etype;
            IItem item  = innerList[index];

            if (index < this.innerList.Length && item != null)
            {
                if (index >= (int)InventorySlot.Inventory1)
                {
                    Remaining++;
                }
                else     // equiped item so remove modifier
                {
                    if (innerList[index].Modifier != null)
                    {
                        innerList[index].Modifier.Unapply(stats);
                    }
                }
                innerList[index] = null;
            }
            return(item);
        }
Ejemplo n.º 8
0
        public bool Swap(InventorySlot primaryIndex, InventorySlot secondaryIndex, IEntityStats stats)
        {
            bool  success       = true;
            IItem primaryItem   = this.Get(primaryIndex, stats);
            IItem secondaryItem = this.Get(secondaryIndex, stats);

            if (primaryItem != null)
            {
                success = this.Set(primaryItem, secondaryIndex, stats);
                if (success && secondaryItem != null)
                {
                    success = this.Set(secondaryItem, primaryIndex, stats);
                    if (!success)
                    {
                        this.Get(secondaryIndex, stats); // take primary back out
                    }
                }
                if (!success)
                {
                    if (primaryItem != null)
                    {
                        this.Set(primaryItem, primaryIndex, stats);
                    }
                    if (secondaryItem != null)
                    {
                        this.Set(secondaryItem, secondaryIndex, stats);
                    }
                }
            }
            else
            {
                success = false;
            }
            // if we did not succeed

            return(success);
        }
Ejemplo n.º 9
0
 public float GetStatWithAppliedSkill(SkillType i, StatType type, IEntityStats stats)
 {
     return(GameGlobal.CalculateSkillEffect(i, type, (float)Math.Floor(skillStats[(int)i]), stats.Get(type)));
 }
Ejemplo n.º 10
0
        public bool Set(IItem item, InventorySlot etype, IEntityStats stats)
        {
            bool success = false;
            int  index   = this.GetEmptyIndex(item, etype);

            // if we have a valid index and valid item
            if (item == null && index >= this.innerList.Length)
            {
                return(false);
            }
            // if we are setting it to a unequiped location
            if (index >= (int)InventorySlot.Inventory1)
            {
                IItem existingItem = innerList[index];
                if (existingItem == null)
                {
                    innerList[index] = item;
                    success          = true;
                    Remaining--;
                }
                else
                {
                    existingItem.Count += item.Count;
                    item.Count          = 0;
                }
            }
            else if (etype == InventorySlot.WieldPrimary || etype == InventorySlot.WieldSecondary || etype == InventorySlot.WieldTwoHanded)
            {
                if (item.Info is IWieldableItemInfo)
                {
                    ItemWieldType itemWieldType = ((IWieldableItemInfo)item.Info).WieldType;
                    // unequip any dual wield item
                    var existingTwoHandedItem = this.Get(InventorySlot.WieldTwoHanded, stats);
                    if (existingTwoHandedItem != null)
                    {
                        this.Set(existingTwoHandedItem, InventorySlot.AnyNonEquiped, stats);
                    }

                    if (itemWieldType == ItemWieldType.OneHand && etype != InventorySlot.WieldTwoHanded)
                    {
                        // if the left hand is empty or we are able to unwield whats in it
                        var existing = this.Get(etype, stats);
                        if (existing != null)
                        {
                            this.Set(existing, InventorySlot.AnyNonEquiped, stats);
                        }
                        innerList[index] = item;
                        success          = true;
                    }
                    else if (itemWieldType == ItemWieldType.BothHands && etype != InventorySlot.WieldTwoHanded)
                    {
                        var existingPrimary = this.Get(InventorySlot.WieldPrimary, stats);
                        if (existingPrimary != null)
                        {
                            this.Set(existingPrimary, InventorySlot.AnyNonEquiped, stats);
                        }
                        var existingSecondary = this.Get(InventorySlot.WieldSecondary, stats);
                        if (existingSecondary != null)
                        {
                            this.Set(existingSecondary, InventorySlot.AnyNonEquiped, stats);
                        }
                        innerList[index] = item;
                        success          = true;
                    }
                }
            }
            else
            {
                //equip code
                if (item.Info is IEquipableItemInfo)
                {
                    innerList[index] = item;
                    success          = true;
                }
            }

            // if success apply the new modifiers
            if (success)
            {
                // apply new modifiers
                if (item.Modifier != null)
                {
                    item.Modifier.Apply(stats);
                }
            }

            return(success);
        }