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;
    }
示例#2
0
    public void TestDeepCopy()
    {
        _slots.Add(_i1);

        // Make sure shallow copy is the same
        InventorySlots shallowCopy = _slots;

        Assert.AreSame(_slots, shallowCopy);

        // Make sure deep copy is different
        InventorySlots deepCopy = _slots.DeepCopy();

        Assert.AreNotSame(_slots, deepCopy);
    }
示例#3
0
        protected override void OnSlotChanged(SyncDictionaryItemSlot.Operation op, int key, ItemSlotData itemSlotData)
        {
            base.OnSlotChanged(op, key, itemSlotData);
            if (itemSlotData.SlotType == ItemSlotType.Any)
            {
                return;
            }
            SlotReferences.TryGetValue(itemSlotData.SlotType, out var equipmentSlotReference);
            InventorySlots.TryGetValue(key, out var itemSlot);
            var equipableSlot = itemSlot as SlotEquipable;

            switch (op)
            {
            case SyncDictionaryItemSlot.Operation.OP_ADD:
                InventorySlots.Add(key, new SlotEquipable(equipmentSlotReference.SlotTransform, itemSlotData, key));
                return;

            case SyncDictionaryItemSlot.Operation.OP_REMOVE:
                InventorySlots.Remove(key);
                return;
            }
            if (equipableSlot == null)
            {
                return;
            }
            equipableSlot.SlotData = itemSlotData;
            equipableSlot.OnSlotChange();

            EquipmentSlotChanged(itemSlotData, equipableSlot);
        }
示例#4
0
    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);
    }
示例#5
0
    /// <summary>
    /// Returns a deep copied instance.
    /// </summary>
    /// <returns>The copy.</returns>
    public InventorySlots DeepCopy()
    {
        InventorySlots deepCopiedInventorySlots = new InventorySlots();

        foreach (var item in _items)
        {
            deepCopiedInventorySlots.Add(item.Key, item.Value.DeepCopy());
        }
        return(deepCopiedInventorySlots);
    }
示例#6
0
        protected override void InitilizeInventorySlots()
        {
            base.InitilizeInventorySlots();
            var count = 0;

            foreach (var equipmentSlot in SlotReferences)
            {
                var equipableSlot = new SlotEquipable(equipmentSlot.Value.SlotTransform, InventorySlotData[count + Capacity], count + Capacity);
                InventorySlots.Add(count + Capacity, equipableSlot);
                count++;
                // call the hook function or it won't initilize the LocalEquips
                if (equipableSlot.SlotData.Occupant())
                {
                    EquipmentSlotChanged(equipableSlot.SlotData, equipableSlot);
                }
            }
        }
 /// <summary>
 /// Adds the item.
 /// </summary>
 /// <param name="item">Item.</param>
 public void AddItem(Item item)
 {
     _inventorySlots.Add(item);
     IncrementAllAttributesText(item);
 }