Beispiel #1
0
        public static Phone GivePhone(Player sender, Player target)
        {
            if (!sender.AccountData.HavePerm("admin.cmds.give.phone"))
            {
                throw new Exception("Vous n'avez pas les permissions pour cela.");
            }

            Phone phone = PhoneHelper.CreatePhone();

            if (PhoneHelper.GetDefaultPhone(target.ActiveCharacter) == null)
            {
                phone.DefaultPhone = true;
            }

            try
            {
                InventoryHelper.AddItemToCharacter(target.ActiveCharacter, phone);

                ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext;
                dbContext.SaveChanges();
                return(phone);
            }
            catch
            {
                PhoneHelper.DeletePhone(phone);
                throw new Exception("Le téléphone n'a pas pu être ajouté à l'utilisateur.");
            }
        }
 private static void PutItemInPlayerHand(Player player)
 {
     try
     {
         Item itemFromGround = ItemHelper.RemoveItemFromGround(player);
         InventoryHelper.AddItemToCharacter(player.ActiveCharacter, itemFromGround);
         Chat.InfoChat(player, "L'objet a été ramassé.");
     }
     catch (Exception e)
     {
         Chat.ErrorChat(player, e.Message);
     }
 }
Beispiel #3
0
        public static void GiveGun(Player sender, Player target, Weapon gun, int ammo)
        {
            if (!sender.AccountData.HavePerm("admin.cmds.give.gun"))
            {
                throw new Exception("Vous n'avez pas les permissions pour cela.");
            }
            if (target.ActiveCharacter.ItemInHand != null)
            {
                throw new Exception("La main du joueur doit être vide.");
            }

            Gun weapon = new Gun(); // Create Gun

            weapon.idWeapon         = gun;
            weapon.Quantity         = ammo;
            weapon.CurrentContainer = null;
            weapon.SpawnLocation    = null;
            weapon.Name             = Weapons.WeaponsDictionnary.GetValueOrDefault((int)gun);
            weapon.ModelId          = WeaponsModelId.WeaponsModelIdDictionnary.GetValueOrDefault((int)gun);
            InventoryHelper.AddItemToCharacter(target.ActiveCharacter, weapon);
        }
        private static void GiveItemToCharacter(Player player, Player receiver)
        {
            Item itemToGive = player.ActiveCharacter.ItemInHand;

            try
            {
                InventoryHelper.RemoveItemFromCharacter(player.ActiveCharacter, player.ActiveCharacter.ItemInHand);
                InventoryHelper.AddItemToCharacter(receiver.ActiveCharacter, itemToGive);

                Chat.InfoChat(player, "L'objet à été donné à " + receiver.ActiveCharacter.Name + ".");
                Chat.InfoChat(receiver, "Vous avez reçu " + itemToGive.Name + " de la part de " + player.ActiveCharacter.Name);
            }
            catch (InventoryAddingExceptions e)
            {
                InventoryHelper.AddItemToCharacter(player.ActiveCharacter, itemToGive);
                Chat.ErrorChat(player, e.Message);
            }
            catch (InventoryRemovingExceptions e)
            {
                Chat.ErrorChat(player, e.Message);
            }
        }
Beispiel #5
0
        public static void ShowContainer(Player player, Container container)
        {
            ServerDbContext dbContext         = ((GameMode)GameMode.Instance).DbContext;
            int             maxSpaceContainer = container.MaxSpace;

            listContainer = new TablistDialog(container.Name + " (" + container.ListItems.Count + "/" + maxSpaceContainer + ")", new[] { "Nom", "Quantité" }, "Sélectionner", "Quitter");

            List <Item> listItemsContainer = container.ListItems;
            int         i = 0;

            foreach (Item item in listItemsContainer)
            {
                listContainer.Add(item.Name, item.Quantity.ToString());
                i++;
            }
            if (i < maxSpaceContainer)
            {
                for (int a = 0; a < (maxSpaceContainer - i); a++)
                {
                    listContainer.Add(Color.DarkGray + " Vide" + Color.White, Color.DarkGray + "0");
                }
            }
            listContainer.Show(player);

            listContainer.Response += (playerReponse, EventArgs) =>
            {
                if (EventArgs.DialogButton == DialogButton.Right)
                {
                    return;
                }
                if (container.ListItems.Count <= EventArgs.ListItem ||
                    container.ListItems[EventArgs.ListItem] == null)   //  Put item in container
                {
                    if (player.ActiveCharacter.ItemInHand != null)
                    {
                        try
                        {
                            if (player.ActiveCharacter.ItemInHand is Gun)
                            {
                                player.SetArmedWeapon(((Gun)player.ActiveCharacter.ItemInHand).idWeapon);
                                player.ActiveCharacter.ItemInHand.Quantity = player.WeaponAmmo;
                            }
                            container.ListItems.Add(player.ActiveCharacter.ItemInHand); // Add item to container
                            ItemHelper.RemoveItemFromPlayerHand(player);
                            dbContext.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            Chat.ErrorChat(player, "Impossible de prendre l'objet.");
                        }
                    }
                }
                else // Take item from container
                {
                    if (player.ActiveCharacter.ItemInHand == null)
                    {
                        try
                        {
                            //ItemHelper.PutItemInPlayerHand(player, container.ListItems[EventArgs.ListItem]);

                            InventoryHelper.AddItemToCharacter(player.ActiveCharacter, container.ListItems[EventArgs.ListItem]);
                            container.ListItems.RemoveAt(EventArgs.ListItem);

                            dbContext.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            Chat.ErrorChat(player, "Impossible de prendre l'objet : " + e.Message);
                        }
                    }
                    else
                    {
                        try
                        {
                            Item itemContainer = container.ListItems[EventArgs.ListItem];
                            Item itemInHand    = player.ActiveCharacter.ItemInHand;

                            container.ListItems.RemoveAt(EventArgs.ListItem);
                            InventoryHelper.RemoveItemFromCharacter(player.ActiveCharacter, player.ActiveCharacter.ItemInHand);

                            container.ListItems.Add(itemInHand);
                            InventoryHelper.AddItemToCharacter(player.ActiveCharacter, itemContainer);
                        }
                        catch (Exception e)
                        {
                            Chat.ErrorChat(player, "Impossible de prendre l'objet : " + e.Message);
                        }
                    }
                }
            };
        }