Inheritance: GameItem
Example #1
0
        public override void Update()
        {
            var items = new ChestItem[Items.Count];

            Items.CopyTo(items);

            if (DateTime.UtcNow.Subtract(start).TotalMinutes < 1 && items.Length > 0)
            {
                foreach (var item in items)
                {
                    if (item.Choices.Count == GUIDs.Count)
                    {
                        GiveItem(item);
                        Items.Remove(item);
                    }
                }
            }
            else
            {
                foreach (var item in items)
                {
                    GiveItem(item);
                    Items.Remove(item);
                }

                GameServer.RemoveGameObject(this);
            }
        }
Example #2
0
    //=====================================================

    #region Private Methods

    void Awake()
    {
        _thisTransform    = this.transform;
        _audioSource      = _thisTransform.GetComponent <AudioSource>();
        _interactPosition = _thisTransform.FindChild("InteractPosition");
        _psChestOpenFx    = _thisTransform.FindChild("psChestOpenFx").GetComponent <ParticleSystem>();
        _chestReward      = _thisTransform.FindChild("ChestItem").GetComponent <ChestItem>();

        _isRewardCollected = false;

        // Set interactive position (offset for player from chest)
        switch (_type)
        {
        case eChestType.SMALL:
            _interactPosition.localPosition = new Vector3(0.0f, 0.0f, 1.0f);
            break;

        case eChestType.MEDIUM:
            _interactPosition.localPosition = new Vector3(0.0f, 0.0f, 1.15f);
            break;

        case eChestType.LARGE:
            _interactPosition.localPosition = new Vector3(0.0f, 0.0f, 1.3f);
            break;
        }
    }
    public void SetItem(ChestItem item, Chest chest)
    {
        if (item == null)
        {
            return;
        }

        //넣을 아이템의 정보
        ItemInfo info = item.item.Info;

        this.item  = item;
        this.chest = chest;


        itemSpriteImage.gameObject.SetActive(true);
        itemSpriteImage.sprite = info.Icon;

        //아이템의 이름 칸에 넣을 문자열
        string nameStr = info.ItemName;

        if (item.item.Info.Count > 1)
        {
            nameStr += (" x" + item.item.Info.Count.ToString());
        }
        itemNameTxt.text = nameStr;
        //===========================
        itemDescTxt.text = info.ItemDesc;
    }
    public void ClickChest(GameObject chest)
    {
        switch (currentStage)
        {
        case Stages.SelectScreen:
            foreach (var item in chests)
            {
                if (item != chest)
                {
                    item.SetActive(false);
                }
            }
            currentStage = Stages.OpenScreen;
            break;

        case Stages.OpenScreen:
            ChestItem newReward = PickRandomItem();
            if (InventoryManager.Instance.FindSeed(newReward.name) != null)
            {
                for (int i = 0; i < newReward.amount; i++)
                {
                    InventoryManager.Instance.AddSeed(newReward.name);
                }
                chest.GetComponent <Image>().sprite = InventoryManager.Instance.FindSeed(newReward.name).sprite;
            }

            if (InventoryManager.Instance.FindFruit(newReward.name) != null)
            {
                for (int i = 0; i < newReward.amount; i++)
                {
                    InventoryManager.Instance.AddFruit(newReward.name, WorldManager.Instance.SelectedIsland.GetComponent <IslandScript>().islandID);
                }
                chest.GetComponent <Image>().sprite = InventoryManager.Instance.FindFruit(newReward.name).sprite;
            }

            if (newReward.amount > 1)
            {
                chest.transform.GetChild(0).gameObject.SetActive(true);
                chest.GetComponentInChildren <TextMeshProUGUI>().text = newReward.amount.ToString();
            }

            InventoryManager.Instance.RemoveChest(currentChest.name);
            currentStage = Stages.ShowScreen;
            break;

        case Stages.ShowScreen:
            foreach (var item in chests)
            {
                item.SetActive(true);
            }
            currentStage = Stages.SelectScreen;
            chestInventory.SetActive(true);
            this.gameObject.SetActive(false);
            break;

        default:
            break;
        }
    }
Example #5
0
 public void SelectItem(ChestItemSlot select)
 {
     foreach (ChestItemSlot slot in slots)
     {
         slot.transform.localScale = Vector3.one;
     }
     select.transform.localScale = Vector3.one * 1.1f;
     selectedItem = select.item;
 }
Example #6
0
    private List <ChestItem> chestItemList = new List <ChestItem>();      //Item列表类

    //初始化商店列表
    public void Init()
    {
        for (int i = 0; i < 3; i++)
        {
            ChestItem item = Instantiate(chestItem, content);
            item.InitItems(coinTransform, initCoinTransform, txtCoinNum, txtPurchaseTips, i + 1);

            chestItemList.Add(item);
        }
    }
Example #7
0
    private void InitChestItems()
    {
        Variables variables = MenuController.instance.variables;

        for (int i = 0; i != chestItems.Length; i++)
        {
            ChestItem chest = chestItems[i];
            if (i == 0)
            {
                chest.button.onClick.AddListener(delegate
                {
                    GetFreeChestItem();
                    if (isCanShow1 || index1 == 1)
                    {
                        index1++;
                        isCanShow1 = false;
                        SDKManager.Instance.ShowAd(ShowAdType.Reward, 1, "免费点击装甲", (bool IsComplete) =>
                        {
                            if (IsComplete)
                            {
                                // GetFreeChestItem();
                            }
                        });
                        Invoke("CanShow1", 60);
                        Invoke("Timer1", 1.0f);
                    }
                    else
                    {
                        Debug.Log("广告请求过于频繁,请在" + (60 - time1) + "秒后再试!");
                        if (60 - time1 == 0)
                        {
                            CancelInvoke("Timer1");
                        }
                        SDKManager.Instance.MakeToast("广告请求过于频繁, 请在" + (60 - time1) + "秒后再试!");
                    }
                });
                continue;
            }
            int price = variables.GetChest(chest.rarity).gemValue;
            chest.price.text = price.ToString();
            chest.button.onClick.AddListener(delegate
            {
                TryPurchase(price, CurrencyType.Gems, delegate
                {
                    TankPrefs.CloudSyncComplete = true;
                    MenuController.ShowMenu <ChestPopup>().OpenChest(chest.rarity, UpdateOfferItems);
                    TankAnalytics.BoughtChest(chest.rarity);
                    TankAnalytics.BoughtWithPremiumCurrency("chest", chest.rarity.ToString(), price);
                });
            });
        }
        UpdateChestItems();
    }
Example #8
0
        public void GiveItem(ChestItem chestItem)
        {
            var need  = new List <Player>();
            var greed = new List <Player>();

            foreach (var player in chestItem.Choices.Keys)
            {
                if (player != null && GameServer.GameObjects.Contains(player))
                {
                    switch (chestItem.Choices[player])
                    {
                    case 1: need.Add(player); break;

                    case 2: greed.Add(player); break;
                    }
                }
            }

            if (need.Count > 0)
            {
                var player = need[Program.Random(need.Count)];
                if (player.AddItem(chestItem.Item))
                {
                    chestItem.Item.OnPickup(player);
                }
                Say(string.Format("{0} won the {1}!", player.Name, chestItem.Item.Name), 1);
            }
            else if (greed.Count > 0)
            {
                var player = greed[Program.Random(greed.Count)];
                if (player.AddItem(chestItem.Item))
                {
                    chestItem.Item.OnPickup(player);
                }
                Say(string.Format("{0} won the {1}!", player.Name, chestItem.Item.Name), 1);
            }

            chestItem.Choices.Clear();
        }
Example #9
0
            public override DialogB Next(Player p, ClientPacket msg)
            {
                var chest = GameObject as Chest;

                msg.ReadByte();
                var option = msg.ReadByte() - 1;

                if (option < chest.Items.Count)
                {
                    var items = new ChestItem[chest.Items.Count];
                    chest.Items.CopyTo(items);

                    var item = items[option];

                    if (item.Choices.ContainsKey(p))
                    {
                        p.Client.SendMessage("You have already rolled on that item");
                        return(null);
                    }

                    var attr = new List <string>();

                    if (item.Item is Equipment)
                    {
                        attr.Add(string.Format("Level {0} {1} {2}", Math.Max(item.Item.Level, 1),
                                               item.Item.Class, item.Item.GetType().BaseType.Name));
                    }
                    else
                    {
                        if (item.Item.Level > 1)
                        {
                            attr.Add("Level: " + item.Item.Level);
                        }
                        if (item.Item.Class != Profession.Peasant)
                        {
                            attr.Add("Class: " + item.Item.Class);
                        }
                    }

                    if (item.Item.StrMod != 0)
                    {
                        attr.Add("STR: " + item.Item.StrMod);
                    }
                    if (item.Item.IntMod != 0)
                    {
                        attr.Add("INT: " + item.Item.IntMod);
                    }
                    if (item.Item.WisMod != 0)
                    {
                        attr.Add("WIS: " + item.Item.WisMod);
                    }
                    if (item.Item.ConMod != 0)
                    {
                        attr.Add("CON: " + item.Item.ConMod);
                    }
                    if (item.Item.DexMod != 0)
                    {
                        attr.Add("DEX: " + item.Item.DexMod);
                    }
                    if (item.Item.HitMod != 0)
                    {
                        attr.Add("HIT: " + item.Item.HitMod);
                    }
                    if (item.Item.DmgMod != 0)
                    {
                        attr.Add("DMG: " + item.Item.DmgMod);
                    }
                    if (item.Item.MaximumHpMod != 0)
                    {
                        attr.Add("HP: " + item.Item.MaximumHpMod);
                    }
                    if (item.Item.MaximumMpMod != 0)
                    {
                        attr.Add("MP: " + item.Item.MaximumMpMod);
                    }
                    if (item.Item.ArmorClassMod != 0)
                    {
                        attr.Add("AC: " + item.Item.ArmorClassMod);
                    }
                    if (item.Item.MagicResistanceMod != 0)
                    {
                        attr.Add("MR: " + item.Item.MagicResistanceMod);
                    }
                    if (item.Item.MaximumAttackPowerMod != 0)
                    {
                        attr.Add(string.Format("Attack Power: {0}-{1}", item.Item.MinimumAttackPowerMod, item.Item.MaximumAttackPowerMod));
                    }
                    if (item.Item.MaximumMagicPowerMod != 0)
                    {
                        attr.Add(string.Format("Magic Power: {0}-{1}", item.Item.MinimumMagicPowerMod, item.Item.MaximumMagicPowerMod));
                    }

                    var dialog = new LootItemDialog();
                    dialog.ChestItem   = item;
                    dialog.Message     = string.Join(", ", attr);
                    dialog.CustomName  = item.Item.Name;
                    dialog.CustomImage = (ushort)(item.Item.Sprite + 0x8000);
                    return(dialog);
                }

                return(null);
            }
Example #10
0
 public void SetChest(ChestItem chext) //Sets current ChestItem 'chest'
 {
     this.chest = chext;
 }
Example #11
0
 void Init()
 {
     selectedItem = null;
     SetNewItem(new ChestItem(GetItem <MachineGunItem>(), 1, 3), new ChestItem(GetItem <WoodenShortbowItem>()));
 }
        public void EquipArmour(ArmourItem armourItem)
        {
            #region Base Stats

            _playerAbilitySystem.strength     += armourItem.strengthAmount;
            _playerAbilitySystem.intelligence += armourItem.intelligenceAmount;
            _playerAbilitySystem.strengthPhysicalDamageIncreaseAmount      += armourItem.physicalArmour;
            _playerAbilitySystem.intelligenceElementalDamageIncreaseAmount += armourItem.elementalArmour;

            switch (armourItem.healthAmount)
            {
            case > 0:
                _player.maxHp += armourItem.healthAmount;
                break;

            case < 0:
                _player.maxHp -= armourItem.healthAmount;
                break;
            }

            switch (armourItem.manaAmount)
            {
            case > 0:
                _playerAbilitySystem.maxMana += armourItem.manaAmount;
                break;

            case < 0:
                _playerAbilitySystem.maxMana -= armourItem.manaAmount;
                break;
            }

            switch (armourItem.strengthAmount)
            {
            // Update Player Stats
            case < 0:
                _player.maxHp -= (_playerAbilitySystem.strengthHpIncreaseAmount * _playerAbilitySystem.strength);
                break;

            case > 0:
                _player.maxHp += (_playerAbilitySystem.strengthHpIncreaseAmount * _playerAbilitySystem.strength);
                break;
            }

            switch (armourItem.intelligenceAmount)
            {
            case < 0:
                _playerAbilitySystem.maxMana -= _playerAbilitySystem.intelligenceManaIncreaseAmount * _playerAbilitySystem.intelligence;
                break;

            case > 0:
                _playerAbilitySystem.maxMana += _playerAbilitySystem.intelligenceManaIncreaseAmount * _playerAbilitySystem.intelligence;
                break;
            }

            #endregion

            // ## HELMET ITEM ##
            if (armourItem is HelmetItem helmetItem)
            {
                head = helmetItem;
                _playerAbilitySystem.manaRegenerationPercentage += helmetItem.manaRegenerationPercentage;
                _player.GetComponent <SkillsManager>().activeSkills.ForEach(skill => skill.manaCost -= helmetItem.reducedManaCostOfSkillsAmount);
                _playerAbilitySystem.reducedManaCostOfSkillsAmount += helmetItem.reducedManaCostOfSkillsAmount;
            }

            // ## CHEST ITEM ##
            if (armourItem is ChestItem chestItem)
            {
                chest = chestItem;
                _playerAbilitySystem.healthOnHitAmount += chestItem.healthOnHitAmount;
                if (_playerAbilitySystem.GetComponent <PlayerEquipmentManager>().hasWeaponEquipped)
                {
                    _playerAbilitySystem.GetComponent <PlayerEquipmentManager>().weaponItem.weaponRange += chestItem.additionalWeaponRangeAmount;
                }
            }

            if (armourItem is BootItem bootItem)
            {
                boots = bootItem;
                _playerAbilitySystem.moveSpeedIncreaseAmount += bootItem.moveSpeedIncrease;
                // Increase Movement Speed
                GetComponent <NavMeshAgent>().speed += (bootItem.moveSpeedIncrease / 100 * GetComponent <NavMeshAgent>().speed);
            }

            // ## Add Armour to Equipment Inventory ##
            _equipmentInventory.AddItem(armourItem);
        }
        // public void EquipHelmet(HelmetItem helmetItem)
        // {
        //     head = helmetItem;
        //     _playerAbilitySystem.strength += helmetItem.strengthAmount;
        //     _playerAbilitySystem.intelligence += helmetItem.intelligenceAmount;
        //
        //     _playerAbilitySystem.strengthPhysicalDamageIncreaseAmount += helmetItem.physicalArmour;
        //     _playerAbilitySystem.intelligenceElementalDamageIncreaseAmount += helmetItem.elementalArmour;
        //     _playerAbilitySystem.manaRegenerationPercentage += helmetItem.manaRegenerationPercentage;
        //
        //     switch (helmetItem.strengthAmount)
        //     {
        //         // Update Player Stats
        //         case < 0:
        //             _player.maxHp -= (_playerAbilitySystem.strengthHpIncreaseAmount * _playerAbilitySystem.strength);
        //             break;
        //         case > 0:
        //             _player.maxHp += (_playerAbilitySystem.strengthHpIncreaseAmount * _playerAbilitySystem.strength);
        //             break;
        //     }
        //
        //     switch (helmetItem.intelligenceAmount)
        //     {
        //         case < 0:
        //             _playerAbilitySystem.maxMana -= _playerAbilitySystem.intelligenceManaIncreaseAmount * _playerAbilitySystem.intelligence;
        //             break;
        //         case > 0:
        //             _playerAbilitySystem.maxMana += _playerAbilitySystem.intelligenceManaIncreaseAmount * _playerAbilitySystem.intelligence;
        //             break;
        //     }
        //
        //     switch (helmetItem.healthAmount)
        //     {
        //         case > 0:
        //             _player.maxHp += helmetItem.healthAmount;
        //             break;
        //         case < 0:
        //             _player.maxHp -= helmetItem.healthAmount;
        //             break;
        //     }
        //
        //     switch (helmetItem.manaAmount)
        //     {
        //         case > 0:
        //             _playerAbilitySystem.maxMana += helmetItem.manaAmount;
        //             break;
        //         case < 0:
        //             _playerAbilitySystem.maxMana -= helmetItem.manaAmount;
        //             break;
        //     }
        //
        //     _equipmentInventory.AddItem(helmetItem);
        // }

        // public void EquipChest(ChestItem chestItem)
        // {
        //     chest = chestItem;
        //     _playerAbilitySystem.strength += chestItem.strengthAmount;
        //     _playerAbilitySystem.intelligence += chestItem.intelligenceAmount;
        //
        //     _playerAbilitySystem.strengthPhysicalDamageIncreaseAmount += chestItem.physicalArmour;
        //     _playerAbilitySystem.intelligenceElementalDamageIncreaseAmount += chestItem.elementalArmour;
        //
        //     switch (chestItem.strengthAmount)
        //     {
        //         // Update Player Stats
        //         case < 0:
        //             _player.maxHp -= (_playerAbilitySystem.strengthHpIncreaseAmount * _playerAbilitySystem.strength);
        //             break;
        //         case > 0:
        //             _player.maxHp += (_playerAbilitySystem.strengthHpIncreaseAmount * _playerAbilitySystem.strength);
        //             break;
        //     }
        //
        //     switch (chestItem.intelligenceAmount)
        //     {
        //         case < 0:
        //             _playerAbilitySystem.maxMana -= _playerAbilitySystem.intelligenceManaIncreaseAmount * _playerAbilitySystem.intelligence;
        //             break;
        //         case > 0:
        //             _playerAbilitySystem.maxMana += _playerAbilitySystem.intelligenceManaIncreaseAmount * _playerAbilitySystem.intelligence;
        //             break;
        //     }
        //
        //     switch (chestItem.healthAmount)
        //     {
        //         case > 0:
        //             _player.maxHp += chestItem.healthAmount;
        //             break;
        //         case < 0:
        //             _player.maxHp -= chestItem.healthAmount;
        //             break;
        //     }
        //
        //     switch (chestItem.manaAmount)
        //     {
        //         case > 0:
        //             _playerAbilitySystem.maxMana += chestItem.manaAmount;
        //             break;
        //         case < 0:
        //             _playerAbilitySystem.maxMana -= chestItem.manaAmount;
        //             break;
        //     }
        //
        //     if (_playerAbilitySystem.GetComponent<PlayerEquipmentManager>().weaponItem != null)
        //         _playerAbilitySystem.GetComponent<PlayerEquipmentManager>().weaponItem.weaponRange += chestItem.additionalWeaponRangeAmount;
        //
        //     _equipmentInventory.AddItem(chestItem);
        // }

        public void UnEquip(Item item)
        {
            equipmentInventoryUI.hoverInterface.SetActive(false);
            _equipmentInventory.RemoveItem(item);

            if (item is WeaponItem)
            {
                hasWeaponEquipped = false;
                weaponItem        = null;
                _playerInventory.AddItem(item);

                // Remove weapon from player's hands
                Destroy(playerWeaponHolsterTransform.gameObject.GetComponentInChildren <EnemyHitDetection>().gameObject);
            }

            if (item is ArmourItem armourItem)
            {
                switch (armourItem.healthAmount)
                {
                case > 0:
                    _player.maxHp -= armourItem.healthAmount;
                    break;

                case < 0:
                    _player.maxHp += armourItem.healthAmount;
                    break;
                }

                switch (armourItem.manaAmount)
                {
                case > 0:
                    _playerAbilitySystem.maxMana -= armourItem.manaAmount;
                    break;

                case < 0:
                    _playerAbilitySystem.maxMana += armourItem.manaAmount;
                    break;
                }

                switch (armourItem.strengthAmount)
                {
                // Update Player Stats
                case < 0:
                    _player.maxHp += (_playerAbilitySystem.strengthHpIncreaseAmount * _playerAbilitySystem.strength);
                    break;

                case > 0:
                    _player.maxHp -= (_playerAbilitySystem.strengthHpIncreaseAmount * _playerAbilitySystem.strength);
                    break;
                }

                switch (armourItem.intelligenceAmount)
                {
                case < 0:
                    _playerAbilitySystem.maxMana += _playerAbilitySystem.intelligenceManaIncreaseAmount * _playerAbilitySystem.intelligence;
                    break;

                case > 0:
                    _playerAbilitySystem.maxMana -= _playerAbilitySystem.intelligenceManaIncreaseAmount * _playerAbilitySystem.intelligence;
                    break;
                }

                // ## HELMET ITEM ##
                if (armourItem is HelmetItem helmetItem)
                {
                    head = null;
                    _playerAbilitySystem.manaRegenerationPercentage -= helmetItem.manaRegenerationPercentage;
                    _player.GetComponent <SkillsManager>().activeSkills.ForEach(skill => skill.manaCost -= helmetItem.reducedManaCostOfSkillsAmount);
                    _playerAbilitySystem.reducedManaCostOfSkillsAmount -= helmetItem.reducedManaCostOfSkillsAmount;
                }

                // ## CHEST ITEM ##
                if (armourItem is ChestItem chestItem)
                {
                    chest = null;
                    _playerAbilitySystem.healthOnHitAmount -= chestItem.healthOnHitAmount;
                    if (_playerAbilitySystem.GetComponent <PlayerEquipmentManager>().hasWeaponEquipped)
                    {
                        _playerAbilitySystem.GetComponent <PlayerEquipmentManager>().weaponItem.weaponRange -= chestItem.additionalWeaponRangeAmount;
                    }
                }

                if (armourItem is BootItem bootItem)
                {
                    boots = null;
                    _playerAbilitySystem.moveSpeedIncreaseAmount -= bootItem.moveSpeedIncrease;
                    // Increase Movement Speed
                    GetComponent <NavMeshAgent>().speed -= (bootItem.moveSpeedIncrease / 100 * _basePlayerMoveSpeed);
                }

                _playerAbilitySystem.strength     -= armourItem.strengthAmount;
                _playerAbilitySystem.intelligence -= armourItem.intelligenceAmount;
                _playerAbilitySystem.strengthPhysicalDamageIncreaseAmount      -= armourItem.physicalArmour;
                _playerAbilitySystem.intelligenceElementalDamageIncreaseAmount -= armourItem.elementalArmour;

                _playerInventory.AddItem(item);
            }

            // Double check to make sure player's HP is not over the maximum
            if (_player.CurrentHp > _player.maxHp)
            {
                _player.CurrentHp = _player.maxHp;
            }
        }
Example #14
0
 //Sets current ChestItem 'chest'
 public void SetChest(ChestItem chext)
 {
     this.chest = chext;
 }