Example #1
0
    public void ApplyLoadedData(object data)
    {
        var d = data as DSPlayerSquad;

        if (d == null)
        {
            d = new DSPlayerSquad();
        }

        firstConsumable.ApplyLoadedData(d.firstConsumable);
        secondConsumable.ApplyLoadedData(d.secondConsumable);

        inventory = d.inventory;


        count  = d.count;
        health = d.health;

        helmetStack = new EquipmentStack(d.Helmet);
        bodyStack   = new EquipmentStack(d.Body);
        shieldStack = new EquipmentStack(d.Shield);
        weaponStack = new EquipmentStack(d.Weapon);

        isEmpty = d.isEmpty;

        //призагрузке надо пройтись по спрайтам и обновить. так как они сериальзуются по id а не по содержимому
        ResetIcons();
    }
Example #2
0
    public void SetSquadValues(Squad squad)
    {
        isEmpty = false;

        var inv = squad.Inventory;

        helmetStack      = new EquipmentStack(inv.Helmet);
        bodyStack        = new EquipmentStack(inv.Body);
        shieldStack      = new EquipmentStack(inv.Shield);
        weaponStack      = new EquipmentStack(inv.Weapon);
        firstConsumable  = new ConsumableStack(inv.FirstConsumable);
        secondConsumable = new ConsumableStack(inv.SecondConsumable);

        inventory = new EquipmentStack[inv.Length];
        for (int i = 0; i < inv.Length; i++)
        {
            inventory[i] = inv[i];
        }

        count  = squad.UnitCount;
        health = new float[count];
        var poss = squad.UnitPositions;

        for (int i = 0; i < count; i++)
        {
            health[i] = poss[i].Unit.Health;
        }
    }
Example #3
0
 void Inventory_OnEquipmentChanged(EquipmentStack obj)
 {
     if (obj != null && !obj.EquipmentStats.Empty && obj.EquipmentStats.Type == EquipmentStats.TypeOfEquipment.SHIELD)
     {
         gameObject.SetActive(false);
     }
 }
Example #4
0
    void ResetIcon(EquipmentStack stack)
    {
        var mp = stack.EquipmentMainProperties;

        mp.ResetIcon();
        stack.EquipmentMainProperties = mp;
    }
    public void AddToInventory(EquipmentStack stack)
    {
        bool stackFinded = false;

        foreach (var inv in inventory)
        {
            if (stack.EquipmentStats.Type == inv.EquipmentStats.Type &&
                stack.EquipmentStats.Id == inv.EquipmentStats.Id &&
                stack.EquipmentStats.ItemDurability == inv.EquipmentStats.ItemDurability)
            {
                stackFinded = true;
                inv.PushItems(stack);
                break;
            }
        }


        if (!stackFinded)
        {
            //if stack not finded
            //we need to add new stack if there are enough space for it
            var thisItemTypeCnt = inventory.Count(s => s.EquipmentStats.Type == stack.EquipmentStats.Type);
            if (thisItemTypeCnt < items.Count)
            {
                inventory.Add(stack);
            }
            else
            {
                throw new System.Exception("больше нет места в инвентаре");
            }
        }
    }
    public override bool CanGetFromThisIventory(AStack aStack, AStack stackForReplacement)
    {
        EquipmentStack stack = aStack as EquipmentStack;

        float summ = stack.EquipmentStats.Cost * stack.Count;

        EquipmentStack stackForReplace;

        if (stackForReplacement != null)
        {
            stackForReplace = stackForReplacement as EquipmentStack;
            if (!stackForReplace.EquipmentStats.Empty && stack.EquipmentMainProperties.Currency == stackForReplace.EquipmentMainProperties.Currency)
            {
                summ -= stackForReplace.EquipmentStats.Cost * stackForReplace.Count;
            }

            if (summ < 0)
            {
                summ = 0;
            }
        }

        if (GameManager.Instance.SavablePlayerData.PlayerProgress.Score.EnoughtMoney(summ, stack.EquipmentMainProperties.Currency))
        {
            return(true);
        }
        else
        {
            Toast.Instance.Show(GameManager.Instance.SavablePlayerData.PlayerProgress.Score.NotEoughtMoveyWarningString(stack.EquipmentMainProperties.Currency));
            return(false);
        }
    }
    public void RemoveFtomInventory(EquipmentStack stack)
    {
        bool           t        = false;
        EquipmentStack toRemove = null;

        foreach (var inv in inventory)
        {
            if (stack.EquipmentStats.Type == inv.EquipmentStats.Type &&
                stack.EquipmentStats.Id == inv.EquipmentStats.Id &&
                stack.EquipmentStats.ItemDurability == inv.EquipmentStats.ItemDurability)
            {
                t = true;
                inv.PopItems(stack.Count);
                if (inv.Count == 0)
                {
                    toRemove = inv;
                }
                break;
            }
        }
        inventory.Remove(toRemove);

        if (!t)
        {
            throw new System.Exception("Алё. Таких предметов в магазине нет!");
        }
    }
    override public void OnDrop(PointerEventData eventData)
    {
        if (CanDrop)
        {
            DragEquipment drag = eventData.pointerDrag.GetComponent <DragEquipment>();

            if (drag != null && drag.CanDrag)
            {
                ADropToMe oldParentDrop = drag.OldParent.GetComponent <ADropToMe>();

                //если перетащили откуда либо кроме самого магазина
                if (!(oldParentDrop is DropToEquipmentMarket) && !(oldParentDrop is DropToConsumableMarket))
                {
                    EquipmentStack stack = new EquipmentStack(drag.EquipStack.EquipmentMainProperties, drag.EquipStack.EquipmentStats, drag.EquipStack.Count);
                    if (oldParentDrop.CanGetFromThisIventory(stack, null))
                    {
                        if (AddToThisInventory(stack))
                        {
                            oldParentDrop.RemoveFromThisInventory(stack);
                        }
                    }

                    Destroy(drag.gameObject);
                    RefreshUI();
                }
            }
        }
    }
Example #9
0
    public override void OnDrop(PointerEventData eventData)
    {
        if (CanDrop)
        {
            DragEquipment drag = eventData.pointerDrag.GetComponent <DragEquipment>();

            if (drag != null && drag.CanDrag)
            {
                ADropToMe oldParentDrop = drag.OldParent.GetComponent <ADropToMe>();

                //если перетащили откуда либо на пол
                if (!(oldParentDrop is DropToGround))
                {
                    //если передащили на заполненную клетку
                    EquipmentStack stack = new EquipmentStack(drag.EquipStack.EquipmentMainProperties, drag.EquipStack.EquipmentStats, drag.EquipStack.Count);
                    if (oldParentDrop.CanGetFromThisIventory(drag.EquipStack, null))
                    {
                        if (AddToThisInventory(drag.EquipStack))
                        {
                            oldParentDrop.RemoveFromThisInventory(drag.EquipStack);
                        }
                    }

                    Destroy(drag.gameObject);
                    RefreshUI();
                }
            }
        }
    }
Example #10
0
 void EquipmentChanged(EquipmentStack eq)
 {
     if (OnEquipmentChanged != null)
     {
         OnEquipmentChanged(eq);
     }
 }
Example #11
0
    public override bool RemoveFromThisInventory(AStack aStack)
    {
        EquipmentStack stack = aStack as EquipmentStack;

        var stats = stack.EquipmentStats;

        //очищаем инвентарь
        if (stats.Type == EquipmentStats.TypeOfEquipment.HEAD)
        {
            Squad.playerSquadInstance.Inventory.Helmet = null;
        }
        else if (stats.Type == EquipmentStats.TypeOfEquipment.SHIELD)
        {
            Squad.playerSquadInstance.Inventory.Shield = null;
        }
        else if (stats.Type == EquipmentStats.TypeOfEquipment.BODY)
        {
            Squad.playerSquadInstance.Inventory.Body = null;
        }
        else if (stats.Type == EquipmentStats.TypeOfEquipment.WEAPON)
        {
            throw new Exception("Нельзя выбрасывать оружие вручную");
        }

        return(true);
    }
    public void PickUpEquipment(EquipmentStack stack)
    {
        int q = 0;

        for (int i = 0; i < hitCount; i++)
        {
            DroppedItem di = rhits[i].transform.GetComponent <DroppedItem>();

            if (di.Stack.EquipmentStats.Type == stack.EquipmentStats.Type &&
                di.Stack.EquipmentStats.Id == stack.EquipmentStats.Id &&
                di.Stack.EquipmentStats.ItemDurability == stack.EquipmentStats.ItemDurability)
            {
                q += di.Stack.Count;

                if (q > stack.Count)
                {
                    di.Stack.PopItems(di.Stack.Count - (q - stack.Count));
                    q = stack.Count;
                }
                else
                {
                    Destroy(di.gameObject);
                }
            }

            if (q == stack.Count)
            {
                break;
            }
        }
    }
Example #13
0
    public override bool RemoveFromThisInventory(AStack aStack)
    {
        EquipmentStack stack = aStack as EquipmentStack;

        //очищаем инвентарь
        if (stack.EquipmentStats.Type == Squad.playerSquadInstance.Inventory[CellIndex].EquipmentStats.Type &&
            stack.EquipmentStats.Id == Squad.playerSquadInstance.Inventory[CellIndex].EquipmentStats.Id &&
            stack.EquipmentStats.ItemDurability == Squad.playerSquadInstance.Inventory[CellIndex].EquipmentStats.ItemDurability)
        {
            if (stack.Count == Squad.playerSquadInstance.Inventory[CellIndex].Count)
            {
                Squad.playerSquadInstance.Inventory[CellIndex] = null;
            }
            else
            {
                Squad.playerSquadInstance.Inventory[CellIndex].PopItems(stack.Count);
            }
        }
        else
        {
            throw new System.Exception("Нельзя удалить из ячейки предметы, которые там не лежат");
        }

        return(true);
    }
Example #14
0
    public override bool RemoveFromThisInventory(AStack aStack)
    {
        EquipmentStack stack = aStack as EquipmentStack;

        EnvirinmantInventoryUI.Instance.PickUpEquipment(stack);

        return(true);
    }
Example #15
0
    public override void OnDrop(PointerEventData eventData)
    {
        if (CanDrop)
        {
            DragEquipment drag = eventData.pointerDrag.GetComponent <DragEquipment>();

            if (drag != null && drag.CanDrag)
            {
                var oldParentDrop = drag.OldParent.GetComponent <ADropToMe>();

                //если в инвентаре есть стак
                if (transform.childCount > 0)
                {
                    DragEquipment thisDrag = transform.GetChild(0).GetComponent <DragEquipment>();

                    //если перетаскиваем на такой же объект, но перетаскиваем не с экипировки
                    if ((drag.EquipStack.EquipmentStats.Type == thisDrag.EquipStack.EquipmentStats.Type &&
                         drag.EquipStack.EquipmentStats.Id == thisDrag.EquipStack.EquipmentStats.Id &&
                         drag.EquipStack.EquipmentStats.ItemDurability == thisDrag.EquipStack.EquipmentStats.ItemDurability) && !(oldParentDrop is DropToEquipment))
                    {
                        //высчитываем кол-во ппедметов, которые можем состакать
                        int cnt = Squad.playerSquadInstance.UnitCount - thisDrag.EquipStack.Count;
                        cnt = cnt <= drag.EquipStack.Count ? cnt : drag.EquipStack.Count;

                        //заносим предметы в инвентарь отряда
                        EquipmentStack stack = new EquipmentStack(thisDrag.EquipStack.EquipmentMainProperties, thisDrag.EquipStack.EquipmentStats, cnt);
                        if (oldParentDrop.CanGetFromThisIventory(stack, thisDrag.EquipStack))
                        {
                            if (AddToThisInventory(stack))
                            {
                                oldParentDrop.RemoveFromThisInventory(stack);
                            }
                        }
                    }
                }
                //если в инвентаре нет стака
                else
                {
                    //высчитываем кол-во ппедметов, которые можем поднять
                    int cnt = drag.EquipStack.Count;
                    cnt = Squad.playerSquadInstance.UnitCount < cnt ? Squad.playerSquadInstance.UnitCount : cnt;
                    EquipmentStack stack = new EquipmentStack(drag.EquipStack.EquipmentMainProperties, drag.EquipStack.EquipmentStats, cnt);

                    if (oldParentDrop.CanGetFromThisIventory(stack, null))
                    {
                        if (AddToThisInventory(stack))
                        {
                            oldParentDrop.RemoveFromThisInventory(stack);
                        }
                    }
                }

                Destroy(drag.gameObject);
                RefreshUI();
            }
        }
    }
Example #16
0
 public EquipmentStack(EquipmentStack itemStackToCopy) : this()
 {
     if (itemStackToCopy != null)
     {
         this.equipmentMainProperties = itemStackToCopy.equipmentMainProperties;
         this.equipmentStats          = itemStackToCopy.equipmentStats;
         this.count = itemStackToCopy.count;
     }
 }
Example #17
0
    private void Inventory_OnEquipmentChanged(EquipmentStack obj)
    {
        var    w   = Others.GetWeightByMass(squad.UnitStats.EquipmentMass);
        Sprite ico = null;
        int    cnt = 0;

        if (w == UnitStats.EquipmentWeight.VERY_LIGHT)
        {
            ico = lightWeight;
            cnt = 1;
        }
        else if (w == UnitStats.EquipmentWeight.VERY_HEAVY)
        {
            ico = heavyWeight;
            cnt = 3;
        }
        else
        {
            ico = mediumWeight;
            if (w == UnitStats.EquipmentWeight.HEAVY)
            {
                cnt = 3;
            }
            else if (w == UnitStats.EquipmentWeight.MEDIUM)
            {
                cnt = 2;
            }
            else
            {
                cnt = 1;
            }
        }

        for (int i = 0; i < 3; i++)
        {
            if (i < cnt)
            {
                var img = weightIcons[i].sprite = ico;
                weightIcons[i].gameObject.SetActive(true);
            }
            else
            {
                weightIcons[i].gameObject.SetActive(false);
            }
        }

        var ind = weightIcons[0].transform.parent.GetComponent <SquadPropertyIndicator>();
        var d   = new Description();

        d.Name = w.GetNameLocalize();
        d.Desc = LocalizedStrings.weight_description;
        ind.Present(null, d);

        Squad_OnModifiersListChanged(squad.StatsModifiers);
        Squad_OnTerrainModifiersListChanged(squad.TerrainStatsModifiers);
    }
Example #18
0
 public void PushItems(EquipmentStack stack)
 {
     if (stack.equipmentStats.Type == this.equipmentStats.Type &&
         stack.equipmentStats.Id == this.equipmentStats.Id &&
         stack.equipmentStats.ItemDurability == this.equipmentStats.ItemDurability)
     {
         this.count += stack.Count;
     }
     else
     {
         throw new System.Exception("Тип или Id предметов, которые Вы пытаетесь стакать, разные. Нельзя стакать разные предметы.");
     }
 }
    public void DropEquipment(EquipmentStack stack, Transform sender, float randmizePosition = 0)
    {
        Vector3 pos = sender.position;

        if (randmizePosition != 0)
        {
            pos.x += Random.Range(-1f, 1f) * randmizePosition;
            pos.y += Random.Range(-1f, 1f) * randmizePosition;
        }

        DroppedItem di = Instantiate(droppedItemOriginal, pos, sender.rotation, DroppedItemsContainer).GetComponent <DroppedItem>();

        di.Stack = new EquipmentStack(stack.EquipmentMainProperties, stack.EquipmentStats, stack.Count);
    }
Example #20
0
    public override bool AddToThisInventory(AStack aStack)
    {
        EquipmentStack stack = aStack as EquipmentStack;

        if (stack.Count == 0)
        {
            return(false);
        }

        //возможно, надо переписать так, чтобы дропал этот скрипт, а не скрипт отряда
        Squad.playerSquadInstance.DropEquipment(stack);

        return(true);
    }
    public void AddEq(EquipmentStack stack)
    {
        var playerEq = GameManager.Instance.SavablePlayerData.PlayerProgress.Equipment;

        var item = Instantiate(itemOriginal, transform);

        if (tempValues)
        {
            item.Present(stack);
        }
        else
        {
            item.Present(stack, playerEq.IsThisEquipmantAllowed(stack.EquipmentStats));
        }
    }
    public override bool RemoveFromThisInventory(AStack aStack)
    {
        EquipmentStack stack = aStack as EquipmentStack;

        float summ = stack.EquipmentStats.Cost * stack.Count;

        summ = (float)Math.Truncate(summ);

        GameManager.Instance.SavablePlayerData.PlayerProgress.Score.SpendMoney(summ, stack.EquipmentMainProperties.Currency);

        // а тут уже удаляем
        MarketInventoryUI.Instance.RemoveFtomInventory(stack);

        return(true);
    }
Example #23
0
    override public void OnDrop(PointerEventData eventData)
    {
        if (CanDrop)
        {
            DragEquipment drag = eventData.pointerDrag.GetComponent <DragEquipment>();

            if (drag != null && drag.CanDrag)
            {
                var oldParentDrop = drag.OldParent.GetComponent <ADropToMe>();
                if (oldParentDrop != this)
                {
                    DragEquipment thisDrag = transform.GetChild(0).GetComponent <DragEquipment>();
                    //в этой ячейке полюбому должен быть inventoryItem
                    if (drag.EquipStack.EquipmentStats.Type == thisDrag.EquipStack.EquipmentStats.Type &&
                        (drag.EquipStack.EquipmentStats.Id != thisDrag.EquipStack.EquipmentStats.Id ||
                         drag.EquipStack.EquipmentStats.ItemDurability != thisDrag.EquipStack.EquipmentStats.ItemDurability))
                    {
                        //если предметов достаточно на весь отряд
                        if (Squad.playerSquadInstance.UnitCount <= drag.EquipStack.Count)
                        {
                            EquipmentStack stack = new EquipmentStack(drag.EquipStack.EquipmentMainProperties, drag.EquipStack.EquipmentStats, Squad.playerSquadInstance.UnitCount);
                            if (oldParentDrop.CanGetFromThisIventory(stack, thisDrag.EquipStack))
                            {
                                if (AddToThisInventory(stack))
                                {
                                    oldParentDrop.RemoveFromThisInventory(stack);
                                    if (!thisDrag.EquipStack.EquipmentStats.Empty)
                                    {
                                        oldParentDrop.AddToThisInventory(thisDrag.EquipStack);
                                    }
                                }
                            }

                            Destroy(drag.gameObject);
                            RefreshUI();
                        }
                        else
                        {
                            Toast.Instance.Show(LocalizedStrings.toast_not_enough_equipment_count);
                        }
                    }
                }
            }
        }
    }
Example #24
0
    public void Merge(object data)
    {
        var d = data as DSPlayerSquad;

        inventory = d.inventory;
        count     = d.count;
        health    = d.health;

        helmetStack      = new EquipmentStack(d.Helmet);
        bodyStack        = new EquipmentStack(d.Body);
        shieldStack      = new EquipmentStack(d.Shield);
        weaponStack      = new EquipmentStack(d.Weapon);
        firstConsumable  = new ConsumableStack(d.FirstConsumable);
        secondConsumable = new ConsumableStack(d.SecondConsumable);

        //призагрузке надо пройтись по спрайтам и обновить. так как они сериальзуются по id а не по содержимому
        ResetIcons();
    }
Example #25
0
    public EquipmentStack this[int index]
    {
        get
        {
            return(inventory[index]);
        }

        set
        {
            if (value == null)
            {
                inventory[index] = null;
            }
            else
            {
                inventory[index] = new EquipmentStack(value);
            }
        }
    }
Example #26
0
    public void Present(EquipmentStack stack, bool enabled = true)
    {
        this.stack = stack;

        img.sprite = stack.EquipmentMainProperties.Icon;

        Color c = Color.white;

        if (enabled)
        {
            c.a = 1;
        }
        else
        {
            c.a = 0.2f;
        }

        img.color = c;
    }
Example #27
0
    public override bool AddToThisInventory(AStack aStack)
    {
        EquipmentStack stack = aStack as EquipmentStack;
        var            stats = stack.EquipmentStats;

        if (stats.Type == EquipmentStats.TypeOfEquipment.HEAD)
        {
            Squad.playerSquadInstance.Inventory.Helmet = stack;
        }
        else if (stats.Type == EquipmentStats.TypeOfEquipment.SHIELD)
        {
            if (Squad.playerSquadInstance.Inventory.Weapon.EquipmentStats.CanUseWithShield)
            {
                Squad.playerSquadInstance.Inventory.Shield = stack;
            }
            else
            {
                Toast.Instance.Show(LocalizedStrings.toast_cant_use_with_current_weapon);
                return(false);
            }
        }
        else if (stats.Type == EquipmentStats.TypeOfEquipment.BODY)
        {
            Squad.playerSquadInstance.Inventory.Body = stack;
        }
        else if (stats.Type == EquipmentStats.TypeOfEquipment.WEAPON)
        {
            if (stats.CanUseWithShield || Squad.playerSquadInstance.Inventory.Shield.EquipmentStats.Empty)
            {
                Squad.playerSquadInstance.Inventory.Weapon = stack;
            }
            else
            {
                Toast.Instance.Show(LocalizedStrings.toast_cant_use_with_shield);
                return(false);
            }
        }

        PlayUiEffectForEquipmant();

        return(true);
    }
    public void FillInventory(EquipmentStack stack)
    {
        bool finded = false;

        foreach (var inventoryStack in inventory)
        {
            if (inventoryStack.EquipmentStats.Type == stack.EquipmentStats.Type &&
                inventoryStack.EquipmentStats.Id == stack.EquipmentStats.Id &&
                inventoryStack.EquipmentStats.ItemDurability == stack.EquipmentStats.ItemDurability)
            {
                inventoryStack.PushItems(stack);
                finded = true;
                break;
            }
        }

        if (!finded)
        {
            inventory.Add(new EquipmentStack(stack));
        }
    }
    public override bool AddToThisInventory(AStack aStack)
    {
        EquipmentStack stack = aStack as EquipmentStack;

        if (MarketInventoryUI.Instance.Fill)
        {
            return(false);
        }

        float summ = stack.EquipmentStats.Cost * stack.Count;

        summ = (float)Math.Truncate(summ);

        GameManager.Instance.SavablePlayerData.PlayerProgress.Score.EarnMoney(summ, stack.EquipmentMainProperties.Currency);

        // а тут уже добавояем
        MarketInventoryUI.Instance.AddToInventory(stack);

        //PlayUiEffectForMoney();

        return(true);
    }
    EquipmentStack GetEquipment(EquipmentContainer[] equipments)
    {
        EquipmentStack res = null;

        if (equipments.Length > 0)
        {
            float t     = GameManager.Instance.CurrentLevel.WholeLevelT;
            float val   = equipmentLevelDependency.Evaluate(t);
            int   index = Mathf.RoundToInt(equipmentLevelDependency.Evaluate(t) * (equipments.Length - 1));
            int   l2    = equipments[index].randomEquipment.Length;
            int   l3    = equipments[index].durability.Length;
            if (l2 > 0 && l3 > 0)
            {
                var eq   = equipments[index].randomEquipment[UnityEngine.Random.Range(0, l2)];
                var eqMS = eq.MainPropertie;
                var eqS  = eq.Stats;
                eqS.ItemDurability = equipments[index].durability[UnityEngine.Random.Range(0, l3)];
                res = new EquipmentStack(eqMS, eqS);
            }
        }

        return(res);
    }