Exemplo n.º 1
0
Arquivo: NPC.cs Projeto: vadian/Novus
        public bool Loot(User.User looter, List <string> commands, bool byPassCheck = false)
        {
            bool looted = false;

            if (IsDead())
            {
                List <Items.Iitem> result = new List <Items.Iitem>();
                StringBuilder      sb     = new StringBuilder();

                if (!byPassCheck)
                {
                    //Let's see if who's looting was the killer otherwise we check the time of death
                    //also check if looter is part of a group if so then the group will provide the loot logic.
                    if (!string.Equals(looter.UserID, ((Iactor)this).KillerID, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (!CanLoot(looter.UserID))
                        {
                            //looter not the killer not in group and time to loot has not expired
                            looter.MessageHandler("You did not deal the killing blow and can not loot this corpse at this time.");
                            return(false);
                        }
                    }


                    //let's check if looter is in a group
                    if (!string.IsNullOrEmpty(looter.GroupName))
                    {
                        //looter is part of a group, let's see if the group loot rule is free for all first
                        Groups.Group group = Groups.Groups.GetInstance().GetGroup(looter.GroupName);
                        if (group.GroupRuleForLooting != Groups.GroupLootRule.First_to_loot)
                        {
                            group.Loot(looter, commands, this);
                            return(false);
                        }
                    }
                }

                if (commands.Contains("all"))
                {
                    sb.AppendLine("You loot the following items from " + FirstName + ":");
                    Inventory.GetInventoryAsItemList().ForEach(i => {
                        sb.AppendLine(i.Name);
                        looter.Player.Inventory.AddItemToInventory(Inventory.RemoveInventoryItem(i, this.Equipment));
                    });

                    looted = true;
                }
                else if (commands.Count > 2)                   //the big one, should allow to loot individual item from the inventory
                {
                    string   itemName       = Items.Items.ParseItemName(commands);
                    int      index          = 1;
                    int      position       = 1;
                    string[] positionString = commands[0].Split('.');                     //we are separating based on using the decimal operator after the name of the npc/item
                    if (positionString.Count() > 1)
                    {
                        int.TryParse(positionString[positionString.Count() - 1], out position);
                    }

                    Inventory.GetInventoryAsItemList().ForEach(i => {
                        if (string.Equals(i.Name, itemName, StringComparison.InvariantCultureIgnoreCase) && index == position)
                        {
                            looter.Player.Inventory.AddItemToInventory(Inventory.RemoveInventoryItem(i, this.Equipment));

                            sb.AppendLine("You loot " + i.Name + " from " + FirstName);
                            Rooms.Room.GetRoom(looter.Player.Location).InformPlayersInRoom(string.Format("{0} loots {1} from {3}'s lifeless body.", looter.Player.FirstName, i.Name, FirstName), new List <string>()
                            {
                                ID
                            });
                            index  = -1;                            //we found it and don't need this to match anymore
                            looted = true;
                        }
                        else
                        {
                            index++;
                        }
                    });
                }
                else
                {
                    sb.AppendLine(FirstName + " was carrying: ");
                    Inventory.GetInventoryAsItemList().ForEach(i => sb.AppendLine(i.Name));
                }

                looter.MessageHandler(sb.ToString());
            }
            return(looted);
        }