public void TestLoadData() { // Setup attributes Attribute a1 = new Attribute(AttributeEnums.AttributeType.EXPERIENCE, "EXP", "EXP", "", 50, 0, 100); Attribute a2 = new Attribute(AttributeEnums.AttributeType.LEVEL, "LVL", "LVL", "", 5, 1, 10); _ac.Add(a1); _ac.Add(a2); // Setup inventory slots Item i1 = new Item(0, Item.ItemType.WEAPON, "weapon", "weapon description", "weapon", _ac, InventorySlots.SlotType.RIGHT_HAND, Item.ItemTier.TIER_5, "weapon.jpg", "swordSFX", "swordVFX"); Item i2 = new Item(1, Item.ItemType.ARMOR, "armor", "aermor description", "armor", _ac, InventorySlots.SlotType.BODY, Item.ItemTier.TIER_3, "armor.jpg", "swordSFX", "swordVFX"); _slots.Add(i1); _slots.Add(i2); // Setup abiltiies Ability ability1 = new Ability(0, Ability.AbilityType.ATTACK, "attack", "attack_description", "attackTooltop", "attackIconPath", "attackVfxPath", 0, 0, Ability.TargetTypeEnum.DEFAULT, null); Ability ability2 = new Ability(1, Ability.AbilityType.LAST_RESORT, "lr", "lrDescription", "lrTooltop", "lrIconPath", "lrVfxPath", 0, 0, Ability.TargetTypeEnum.DEFAULT, null); _abilityCollection.Add(ability1); _abilityCollection.Add(ability2); // Setup units _u1.FirstName = "Leonard"; _u1.LastName = "Bedner"; _u1.AttributeCollection = _ac; _u1.Class = "Developer"; _u1.InventorySlots = _slots; _u1.AbilityCollection = _abilityCollection; }
public void TestGetAttackAbility() { _abilityCollection = new AbilityCollection(); _abilityCollection.Add(_ability1); _abilityCollection.Add(_ability2); _abilityCollection.Add(_ability3); Assert.AreSame(_ability3, _abilityCollection.GetAttackAbility()); }
public void TestGetAbilities() { _abilityCollection = new AbilityCollection(); _abilityCollection.Add(_ability1); _abilityCollection.Add(_ability2); _abilityCollection.Add(_ability3); var abilities = _abilityCollection.GetAbilities(); Assert.AreEqual(3, abilities.Count); Assert.AreSame(_ability1, abilities [0]); Assert.AreSame(_ability2, abilities [1]); Assert.AreSame(_ability3, abilities [2]); }
public void TestAdd() { _abilityCollection = new AbilityCollection(); Assert.AreEqual(0, _abilityCollection.Count); _abilityCollection.Add(_ability1); Assert.AreEqual(1, _abilityCollection.Count); }
public void TestDeepCopy() { _abilityCollection = new AbilityCollection(); _abilityCollection.Add(_ability1); _abilityCollection.Add(_ability2); _abilityCollection.Add(_ability3); // Make sure shallow copy is the same AbilityCollection shallowCopy = _abilityCollection; Assert.AreSame(_abilityCollection, shallowCopy); // Make sure deep copy is different AbilityCollection deepCopy = _abilityCollection.DeepCopy(); Assert.AreNotSame(_abilityCollection, deepCopy); }
public void TestGet() { _abilityCollection = new AbilityCollection(); _abilityCollection.Add(_ability1); Ability ability = _abilityCollection.Get(0); Assert.AreSame(_ability1, ability); }
private UnitData( string resRef, string firstName, string lastName, string @class, string portraitLocation, string movementSoundLocation, string sprite, UnitType unitType, Dictionary <AttributeEnums.AttributeType, float> attributes, Dictionary <InventorySlots.SlotType, int> inventory, List <int> abilities ) { ResRef = resRef; FirstName = firstName; LastName = lastName; Class = @class; PortraintLocation = portraitLocation; MovementSoundLocation = movementSoundLocation; Sprite = sprite; Type = unitType; // Set attributes in their collection. If attribute already exists, set value, // else, grab from global collection and set new attribute and value AttributeCollection globalAttributeCollection = AttributeManager.Instance.GlobalAttributeCollection; if (AttributeCollection == null) { AttributeCollection = new AttributeCollection(); } AttributeCollection = AttributeCollection.GetFromGlobalCollection(attributes, globalAttributeCollection, AttributeCollection); // Create inventory slots for unit InventorySlots = new InventorySlots(); foreach (var inventorySlot in inventory) { // Get item from global inventory Item item = ItemManager.Instance.GlobalInventory.GetById(inventorySlot.Value).DeepCopy(); InventorySlots.Add(inventorySlot.Key, item); } // Abilities AbilityCollection = new AbilityCollection(); foreach (var id in abilities) { // Get ability from global instance Ability ability = AbilityManager.Instance.GlobalAbilityCollection.Get(id).DeepCopy(); AbilityCollection.Add(ability); } // Load the portrait Portrait = Resources.Load <Sprite>(PortraintLocation); // Load the sounds MovementSound = Resources.Load <AudioClip>(MovementSoundLocation); }
/// <summary> /// Returns a deep copied instance. /// </summary> /// <returns>The copy.</returns> public AbilityCollection DeepCopy() { AbilityCollection deepCopiedInstance = new AbilityCollection(); foreach (var ability in _abilities.Values) { deepCopiedInstance.Add(ability.DeepCopy()); } return(deepCopiedInstance); }
private void Awake() { abilityInventory.List.Clear(); for (int i = 0; i < abilitySlots.Value; i++) { Ability ability = null; if (i < defaultInventory.Count) { ability = defaultInventory[i]; } else { ability = Ability.CreateInstance <Ability>(); ability.AssignRandomParts(); } abilityInventory.Add(Ability.Instantiate(ability, owner)); } selectedAbility.Value = abilityInventory[0]; }