Esempio n. 1
0
    /// <summary>
    /// Override of UseSlot.
    ///
    /// Sells 1 unit of the item for gold
    /// </summary>
    /// <param name="slot"></param>
    protected override void UseSlot(ItemSlot slot)
    {
        ItemBase item = _inventory.GetItem(slot);

        // check if any item is in the slot
        if (item == null)
        {
            return;
        }

        int cost = item.properties.value * 2;

        // check gold
        if (_buyerInventory.gold < cost)
        {
            return;
        }

        // deduct cost from player
        _buyerInventory.gold -= cost;

        // create item
        ItemDatabase itemDB     = GameDatabase.instance.GetComponent <ItemDatabase>();
        ItemBase     boughtItem = itemDB.GetNewItem(item.properties.itemID, 1);

        // give item to player
        _buyerInventory.AddItem(boughtItem);

        // update gold display
        UpdateGoldText();
    }
Esempio n. 2
0
        public void Steals(int number, string item, Character character)
        {
            CharacterInventory inv = GetComponentInChildren <CharacterInventory>();

            Debug.Assert(inv != null);

            bool hasItem = inv.HasItem(item, number);

            if (!hasItem)
            {
                Debug.LogWarning(this.gameObject.name + " does not have " + number + " " + item);
                return;
            }

            Debug.Assert(number >= 1 && number <= 24);

            CharacterInventory toInv = character.GetComponentInChildren <CharacterInventory>();

            Debug.Assert(toInv != null);

            animator.SetTrigger(Animator.StringToHash("IsInteract"));

            for (int i = 0; i < number; ++i)
            {
                GameObject obj = toInv.GetItem(item);
                Debug.Assert(obj != null);
                PixelItem pixelItem = obj.GetComponent <PixelItem>();
                toInv.AddItem(pixelItem);
                obj.transform.parent = toInv.transform;
            }
        }
Esempio n. 3
0
        public void CreateItem(GameObject item, int quantity = 1)
        {
            Debug.Assert(quantity >= 1 && quantity <= 4);

            for (int i = 0; i < quantity; ++i)
            {
                GameObject newObj = Instantiate(item);
                newObj.gameObject.name = item.name;

                CharacterInventory inv = GetComponentInChildren <CharacterInventory>();
                Debug.Assert(inv != null);

                PixelItem pixelItem = newObj.GetComponent <PixelItem>();

                bool succeed = inv.AddItem(pixelItem);
                if (succeed)
                {
                    newObj.gameObject.SetActive(false);
                    newObj.transform.parent = inv.transform;
                }
                else
                {
                    Destroy(newObj);
                    Debug.LogWarning("Inventory Full");
                }
            }
        }
Esempio n. 4
0
 public void RemoveFromWeapons()
 {
     Debug.Log("RemoveFromWeapons: " + settings.Name);
     if (inventory != null)
     {
         CharacterInventory _inventory = inventory;
         inventory.RemoveWeapon(this);
         _inventory.AddItem(this);
     }
 }
Esempio n. 5
0
    public void EquipButton()
    {
        CharacterInventory inventory = MouseControl.instance.unitOfInterest.GetComponent <CharacterInventory>();

        inventory.RemoveItemByID(item.GetInstanceID());
        Item oldEquip = inventory.EquipNewItem(item);

        inventory.AddItem(oldEquip);

        Finish();
    }
Esempio n. 6
0
    public void EquipButton()
    {
        CharacterInventory inventory = MouseControl.instance.unitOfInterest.GetComponent <CharacterInventory>();

        inventory.RemoveItemByID(currentItem.GetInstanceID());
        Item oldEquip = inventory.EquipNewItem(currentItem);

        inventory.AddItem(oldEquip);

        //Update the items
        ResetButtons();
    }
Esempio n. 7
0
    private void PickInInventory(Item _item)
    {
        if (m_current_selected_object_ != null && m_current_selected_object_.CompareTag("Player"))
        {
            m_charactere_inventory_ = m_current_selected_object_.GetComponent <CharacterInventory>();
        }
        bool t = m_charactere_inventory_.AddItem(m_destination_item_.m_item);

        if (!t)
        {
            Debug.Log("failed");
        }
    }
    //isSwaped mean this equip is swapped by other
    public Equipment Unequip(int slotId)
    {
        if (currentEquipment[slotId] != null)
        {
            Equipment itemInEquip = currentEquipment[slotId];
            // add item back to inventory if current item not weapon
            if (!CheckIsEquipmentWeapon(slotId))
            {
                inventory.AddItem(itemInEquip);
            }

            currentEquipment[slotId] = null;
            if (onEquipmentChanged != null)
            {
                onEquipmentChanged.Invoke(null, itemInEquip);
            }
            return(itemInEquip);
        }
        return(null);
    }
Esempio n. 9
0
        public void Takes(int number, string item, PixelStorage pixelStorage)
        {
            CharacterInventory inv = GetComponentInChildren <CharacterInventory>();

            Debug.Assert(inv != null);

            bool hasItem = pixelStorage.HasObject(item, number);

            if (!hasItem)
            {
                Debug.LogWarning(pixelStorage.name + " does not have " + number + " " + item);
                return;
            }

            Debug.Assert(number >= 1 && number <= 24);
            for (int i = 0; i < number; ++i)
            {
                GameObject obj = pixelStorage.TakeObject(item);
                if (obj == null)
                {
                    break;
                }
                PixelItem pixelItem = obj.GetComponent <PixelItem>();
                Debug.Assert(pixelItem != null);

                bool succeed = inv.AddItem(pixelItem);

                if (succeed)
                {
                    //animator.SetTrigger(Animator.StringToHash("IsPickup"));
                    pixelItem.gameObject.SetActive(false);
                    pixelItem.transform.parent = inv.transform;
                }
            }

            animator.SetTrigger(Animator.StringToHash("IsInteract"));
        }
Esempio n. 10
0
    public void EquipItem()
    {
        CharacterInventory i = currentUnit.GetComponent <CharacterInventory>();

        //Store the old equipment to add back to the inventory
        Item oldEquip = null;

        if (currentItem is Weapon)
        {
            oldEquip = i.equippedWeapon;
        }
        else if (currentItem is Armor)
        {
            oldEquip = i.equippedArmor;
        }

        i.EquipNewItem(currentItem);
        i.RemoveItemByIndex(currentItemIndex);
        i.AddItem(oldEquip);

        ResetItemOptions();
        UpdateItemInfo();
        ResetCurrentItem();
    }
Esempio n. 11
0
        public void InspectObject(PixelCollision pc)
        {
            // Inspected object is a door
            PixelDoor door = pc.pixelCollider.transform.parent.GetComponent <PixelDoor>();

            if (door != null)
            {
                if (door.interactionDirection != Direction.All && pc.direction != Direction.All)
                {
                    if (door.interactionDirection != pc.direction)
                    {
                        return;
                    }
                    if (facingDirection.x > 0 && facingDirection.y > 0 && door.interactionDirection != Direction.NE)
                    {
                        return;
                    }
                    if (facingDirection.x > 0 && facingDirection.y < 0 && door.interactionDirection != Direction.SE)
                    {
                        return;
                    }
                    if (facingDirection.x < 0 && facingDirection.y > 0 && door.interactionDirection != Direction.NW)
                    {
                        return;
                    }
                    if (facingDirection.x < 0 && facingDirection.y < 0 && door.interactionDirection != Direction.SW)
                    {
                        return;
                    }
                }
                animator.SetTrigger(Animator.StringToHash("IsInteract"));
                EnterDoor(door);
                return;
            }

            // Inspected object is an item
            PixelItem item = pc.pixelCollider.transform.parent.GetComponent <PixelItem>();

            if (item != null)
            {
                CharacterInventory inv = GetComponentInChildren <CharacterInventory>();
                Debug.Assert(inv != null);

                bool succeed = inv.AddItem(item);

                if (succeed)
                {
                    animator.SetTrigger(Animator.StringToHash("IsPickup"));
                    item.gameObject.SetActive(false);
                    item.transform.parent = inv.transform;
                }

                return;
            }

            // Inspected object is a character
            currentlySpeakingTo = pc.pixelCollider.transform.parent.GetComponent <Character>();
            if (currentlySpeakingTo == this)
            {
                currentlySpeakingTo = null;                                          // Cannot talk to one self
            }
            if (currentlySpeakingTo != null)
            {
                Talk();
            }
        }
Esempio n. 12
0
        public async Task StartCommand(CommandContext ctx)
        {
            //Vérification de base
            if (dep.Entities.Characters.IsPresent(ctx.User.Id))
            {
                await ctx.RespondAsync(dep.Dialog.GetString("errorAlreadyRegistered"));

                return;
            }
            if (!dep.Entities.Guilds.IsPresent(ctx.Guild.Id))
            {
                return;
            }

            InteractivityModule interactivity = ctx.Client.GetInteractivityModule();

            //Créer Direct Channel (MP)
            DiscordDmChannel channel = await ctx.Member.CreateDmChannelAsync();

            //Création du Character
            Character c = new Character
            {
                Id = ctx.User.Id
            };

            //1 On récupère le truename puis on enregistre directement pour éviter les doublons
            DiscordEmbedBuilder embedTrueName = dep.Embed.CreateBasicEmbed(ctx.User, dep.Dialog.GetString("startIntroAskTruename"),
                                                                           dep.Dialog.GetString("startIntroInfoTruename"));
            await channel.SendMessageAsync(embed : embedTrueName);

            bool trueNameIsValid = false;

            do
            {
                MessageContext msgTrueName = await interactivity.WaitForMessageAsync(
                    xm => xm.Author.Id == ctx.User.Id && xm.ChannelId == channel.Id, TimeSpan.FromMinutes(1));

                if (msgTrueName != null)
                {
                    if (msgTrueName.Message.Content.Length <= 50 &&
                        !dep.Entities.Characters.IsTrueNameTaken(msgTrueName.Message.Content) &&
                        msgTrueName.Message.Content.Length > 2)
                    {
                        c.TrueName = dep.Dialog.RemoveMarkdown(msgTrueName.Message.Content);

                        dep.Entities.Characters.AddCharacter(c);
                        trueNameIsValid = true;
                    }
                    else
                    {
                        DiscordEmbedBuilder embedErrorTrueName = dep.Embed.CreateBasicEmbed(ctx.User, dep.Dialog.GetString("startIntroTrueTaken"));
                        await channel.SendMessageAsync(embed : embedErrorTrueName);
                    }
                }
            } while (!trueNameIsValid);

            //2 On demande le nom
            DiscordEmbedBuilder embedName = dep.Embed.CreateBasicEmbed(ctx.User, dep.Dialog.GetString("startIntroAskName"),
                                                                       dep.Dialog.GetString("startIntroInfoName"));
            await channel.SendMessageAsync(embed : embedName);

            MessageContext msgName = await interactivity.WaitForMessageAsync(
                xm => xm.Author.Id == ctx.User.Id && xm.ChannelId == channel.Id, TimeSpan.FromMinutes(1));

            if (msgName != null)
            {
                c.Name = dep.Dialog.RemoveMarkdown(msgName.Message.Content);
            }

            //3 Puis finalement le sexe
            DiscordEmbedBuilder embedSex = dep.Embed.CreateBasicEmbed(ctx.User, dep.Dialog.GetString("startIntroAskGender"),
                                                                      dep.Dialog.GetString("startIntroInfoGender"));
            await channel.SendMessageAsync(embed : embedSex);

            MessageContext msgSex = await interactivity.WaitForMessageAsync(xm => xm.Author.Id == ctx.User.Id &&
                                                                            (xm.Content.ToLower() == "male" ||
                                                                             xm.Content.ToLower() == "female" &&
                                                                             xm.ChannelId == channel.Id),
                                                                            TimeSpan.FromMinutes(1));

            if (msgSex != null)
            {
                if (msgSex.Message.Content.ToLower() == "male")
                {
                    c.Sex = Sex.Male;
                }
                else
                {
                    c.Sex = Sex.Female;
                }
            }
            else
            {
                c.Sex = Sex.Male;
            }

            //Si le nom a bien été rentré, on créer le personnage
            if (c.Name != null)
            {
                DiscordEmbedBuilder embedFinal = dep.Embed.CreateBasicEmbed(ctx.User, dep.Dialog.GetString("startIntroConclude", c));
                await channel.SendMessageAsync(embed : embedFinal);

                c.Level     = 1;
                c.Energy    = 100;
                c.MaxEnergy = 100;
                c.Location  = dep.Entities.Guilds.GetGuildById(ctx.Guild.Id).SpawnLocation;
                c.Stats     = new CharacterStats
                {
                    Endurance    = 1,
                    Strength     = 1,
                    Intelligence = 1,
                    Agility      = 1,
                    Dexterity    = 1,
                    Health       = 100,
                    MaxHealth    = 100,
                    UpgradePoint = 0
                };


                //INVENTAIRE
                CharacterInventory inv = new CharacterInventory
                {
                    Id = c.Id
                };
                inv.AddMoney(500);
                inv.AddItem(new Wood(10));
                inv.AddItem(new Weapon()
                {
                    Name         = "Awesome sword",
                    Quantity     = 1,
                    AttackDamage = 10,
                    CraftsmanId  = 100,
                    Hand         = 2
                });

                c.Skills.Add(new LoggerSkill());


                dep.Entities.Inventories.AddInventory(inv);

                c.OriginRegionName = dep.Entities.Map.GetRegionByLocation(dep.Entities.Guilds.GetGuildById(ctx.Guild.Id).SpawnLocation).Name;
                c.Profession       = Profession.Peasant;

                dep.Entities.Map.GetCase(c.Location).AddNewCharacter(c);
                dep.Entities.Characters.EditCharacter(c);
            }
            //Sinon on supprime celui qui avait commencé à être créer
            else
            {
                dep.Entities.Characters.DeleteCharacter(c.Id);
            }
        }