public List <Item> GenerateItems()
    {
        LootCollection lootCollect = LootTableData.GetRandomItems(this);

        _generatedItems = lootCollect.randomItems;

        return(_generatedItems);
    }
Exemple #2
0
        public override LootCollection GenerateLootCollection()
        {
            LootCollection coll = new LootCollection("5d10+50");

            coll.AddLoot(new HighMagicAWSTemplate());

            coll.AddLoot(new MedScrollLootSet(1), 25);
            coll.AddLoot(new LesserOrRegularPotionLootSet(0, 3), 25);
            coll.AddLoot(new GemLootSet(1, 4), 0.4, 100);

            return(coll);
        }
Exemple #3
0
    public LootCollection GetRandomItems(LootCrate lootCrate)
    {
        LootCollection lootObj = new LootCollection();

        lootObj.lootTableData = this;
        lootObj.randomDrops   = UnityEngine.Random.Range(minDrops, maxDrops + 1);

        List <Item> items = lootObj.randomItems = new List <Item>();

        for (int r = lootObj.randomDrops; --r >= 0;)
        {
            Item item = RandomizeItem(lootCrate.MagicFind, lootCrate.ItemLevel, lootCrate.Variance);
            items.Add(item);
        }

        return(lootObj);
    }
 /// <summary>
 /// Occurs when closing the loot window.
 /// </summary>
 private void CM_CLEARCORPSE()
 {
     try
     {
         //Release resource
         LootCollection collection = this.character.Tag as LootCollection;
         if (collection != null)
         {
             collection.ReleaseLootLock();
             this.character.Tag = null;
         }
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.ToString());
     }
 }
        public void MakeAStory_When_Called_With_Story_Components_A_Single_Story_Is_Produced()
        {
            LootCollection fakeLootCollection = new LootCollection();
            var            LootList           = new List <LootModel>();

            LootList.Add(new LootModel("Loot", 10));
            fakeLootCollection.Loot = LootList;

            var mockLootRepository = new Mock <IRepository>();

            mockLootRepository
            .Setup(x => x.GetLootCollection())
            .Returns(fakeLootCollection);


            var fakeMonsterCollection = new MonsterCollection();
            var monsterList           = new List <MonsterModel>();

            monsterList.Add(new MonsterModel("Monster", 1, 1, 1, 10));
            fakeMonsterCollection.Monsters = monsterList;

            var mockMonsterRepository = new Mock <IRepository>();

            mockMonsterRepository
            .Setup(x => x.GetMonsterCollection())
            .Returns(fakeMonsterCollection);

            var stubStoryElements = new StoryElements(
                new MonsterFactory(mockMonsterRepository.Object),
                new LootFactory(mockLootRepository.Object),
                new RoomFactory(1, 1));

            stubStoryElements.CreateStoryElements();

            var sut         = new DungeonGenerator.StoryMaker();
            var storyResult = sut.MakeAStory(stubStoryElements);

            var TestStory = $"You stand in a room 1' x 1'.\n"
                            + $"On the far side of the room you see a Monster, \n"
                            + $"guarding a Loot";

            Assert.Equal(TestStory, storyResult);
        }
        public void MakeAStory_When_Called_With_A_Single_Monster_The_Singluar_Joining_Word_Will_Be_Used()
        {
            LootCollection fakeLootCollection = new LootCollection();
            var            LootList           = new List <LootModel>();

            LootList.Add(new LootModel("Loot", 10));
            fakeLootCollection.Loot = LootList;

            var mockLootRepository = new Mock <IRepository>();

            mockLootRepository
            .Setup(x => x.GetLootCollection())
            .Returns(fakeLootCollection);


            var fakeMonsterCollection = new MonsterCollection();
            var monsterList           = new List <MonsterModel>();

            monsterList.Add(new MonsterModel("Monster", 1, 1, 1, 10));
            fakeMonsterCollection.Monsters = monsterList;

            var mockMonsterRepository = new Mock <IRepository>();

            mockMonsterRepository
            .Setup(x => x.GetMonsterCollection())
            .Returns(fakeMonsterCollection);

            var stubStoryElements = new StoryElements(
                new MonsterFactory(mockMonsterRepository.Object),
                new LootFactory(mockLootRepository.Object),
                new RoomFactory(10, 10));

            stubStoryElements.CreateStoryElements();

            var sut         = new StoryMaker();
            var storyResult = sut.MakeAStory(stubStoryElements);

            Assert.Contains("a Monster", storyResult);
        }
        public void GetLoot_When_Called_Returns_A_Singular_Item_Decription_Of_Loot(string expected, int index)
        {
            LootCollection fakeLootCollection = new LootCollection();

            var LootList = new List <LootModel>();

            LootList.Add(new LootModel("A Shiny Thing", 10));
            LootList.Add(new LootModel("Money", 100));
            LootList.Add(new LootModel("Rusted shield", 1));
            fakeLootCollection.Loot = LootList;

            var mockRepository = new Mock <IRepository>();

            mockRepository
            .Setup(x => x.GetLootCollection())
            .Returns(fakeLootCollection);

            var sut    = new LootFactory(mockRepository.Object);
            var result = sut.GetLoot(index);

            Assert.Equal(expected, result.Description);
        }
Exemple #8
0
        public override void GenerateLoot(bool spawning)
        {
            Container pack = Backpack;

            if (pack == null)
            {
                pack         = new Backpack();
                pack.Movable = false;
                AddItem(pack);
            }

            base.GenerateLoot(spawning);

            LootCollection coll = LootSystem.GetCollection(this.GetType());

            if (spawning)
            {
                coll.GenerateGold(this, pack);
            }
            else
            {
                coll.GenerateLoot(this, pack);
            }
        }
Exemple #9
0
 public bool GetLootCollection(Character target, out LootCollection collection)
 {
     collection = LootCollection.Create(this, target);
     return(true);
 }
Exemple #10
0
 public bool GetLootCollection(Character target, out LootCollection collection)
 {
     throw new NotImplementedException();
 }
Exemple #11
0
        /// <summary>
        /// Occurs when a player selects a drop from the droplist.
        /// </summary>
        /// <param name="cpkt"></param>
        private void CM_DROPSELECT(CMSG_DROPSELECT cpkt)
        {
            try
            {
                MapObject      target = null;
                Rag2Collection list   = null;
                LootCollection loot   = this.character.Tag as LootCollection;

                //Corpse disappeared already
                if (!Regiontree.TryFind(cpkt.ActorID, this.character, out target))
                {
                    SMSG_NPCDROPLISTRESULT spkt = new SMSG_NPCDROPLISTRESULT();
                    spkt.ActorID   = cpkt.ActorID;
                    spkt.Result    = 0;
                    spkt.SessionId = this.character.id;
                    this.Send((byte[])spkt);
                    return;
                }
                //Uknown looting error (not implamented itseems)
                else if (loot == null)
                {
                    SMSG_NPCDROPLISTRESULT spkt = new SMSG_NPCDROPLISTRESULT();
                    spkt.ActorID   = cpkt.ActorID;
                    spkt.Result    = 4;
                    spkt.SessionId = this.character.id;
                    this.Send((byte[])spkt);
                    return;
                }
                else
                {
                    list = loot.Lootlist;
                }



                //OBTAIN THE REQUIRED ITEMS FROM THE MERCHANT
                Rag2Item item = list[cpkt.Index];
                if (item == null)
                {
                    return;
                }

                //TEMP HELPER VARIABLES
                int        nstacked     = 0;
                List <int> update_queue = new List <int>();

                //WALKTHROUGH EVERY ITEM AND CHECK IF IT CAN BE STACKED
                foreach (int index in this.character.container.FindAllItems(item.info.item))
                {
                    Rag2Item invItem = this.character.container[index];
                    nstacked += Math.Min(0, (item.info.max_stack - invItem.count));
                    if (invItem.count < item.info.max_stack)
                    {
                        update_queue.Add(index);
                    }
                }

                //CALCULATE THE AMOUNT OF NEW SLOTS REQUIRED
                int req_hslot = (int)item.count % (int)this.character.container.Capacity;
                int req_slots = item.count;
                //int max_stack = (item.info.max_stack == 0) ? 1 : item.info.max_stack;
                if (item.info.max_stack > 0)
                {
                    int div_rem  = (int)((item.count - nstacked) / item.info.max_stack);
                    int div_rem2 = (req_hslot > 0) ? 1 : 0;
                    req_slots = div_rem + div_rem2;
                }

                if (this.character.container.Count + req_slots > this.character.container.Capacity)
                {
                    SMSG_NPCDROPLISTRESULT spkt = new SMSG_NPCDROPLISTRESULT();
                    spkt.ActorID   = cpkt.ActorID;
                    spkt.Result    = 3;
                    spkt.SessionId = this.character.id;
                    this.Send((byte[])spkt);
                    return;
                }


                //AMOUNT USED IN DECREMENT CALCULATIONS
                int amount = (int)item.count;

                //ITERATE THROUGH ALL AVAILABLE ITEM THAT CAN BE PROCESSED FOR UPDATES
                foreach (int invIndex in update_queue)
                {
                    Rag2Item invItem  = this.character.container[invIndex];
                    int      leftover = item.info.max_stack - invItem.count;
                    leftover       = Math.Max(0, Math.Min(amount, leftover));
                    invItem.count += leftover;
                    amount        -= leftover;

                    SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM();
                    spkt.Index        = (byte)invIndex;
                    spkt.UpdateReason = (byte)ItemUpdateReason.Obtained;
                    spkt.UpdateType   = 4;
                    spkt.Container    = 2;
                    spkt.Amount       = (byte)invItem.count;
                    spkt.SessionId    = this.character.id;
                    this.Send((byte[])spkt);
                }

                //ITERATE THROUGH EVERY FREE INDEX AND PROCESS IT
                foreach (int invIndex in this.character.container.FindFreeIndexes())
                {
                    if (amount == 0)
                    {
                        break;
                    }
                    int      leftover = Math.Min(amount, item.info.max_stack);
                    Rag2Item invItem  = item.Clone(leftover);
                    this.character.container[invIndex] = invItem;
                    amount -= leftover;

                    SMSG_ADDITEM spkt = new SMSG_ADDITEM();
                    spkt.Container    = 2;
                    spkt.UpdateReason = (byte)ItemUpdateReason.Obtained;
                    spkt.SetItem(invItem, invIndex);
                    spkt.SessionId = this.character.id;
                    this.Send((byte[])spkt);
                }

                //CHECK THE LIST
                if (amount == 0)
                {
                    list.RemoveAt(cpkt.Index);
                }
                else
                {
                    item.count = amount;
                }

                //REFRESH THE INVENTORY
                loot.Open(this.character, target);
                QuestBase.UserObtainedItem(item.info.item, this.character);

                if (this.character.sessionParty != null)
                {
                    for (int i = 0; i < this.character.sessionParty._Characters.Count; i++)
                    {
                        Character partyTarget = this.character.sessionParty._Characters[i];
                        if (partyTarget.id == this.character.id)
                        {
                            continue;
                        }
                        SMSG_PARTYMEMBERLOOT spkt2 = new SMSG_PARTYMEMBERLOOT();
                        spkt2.SessionId = partyTarget.id;
                        spkt2.Index     = (byte)(i + 1);
                        spkt2.ActorId   = this.character.id;
                        spkt2.ItemId    = item.info.item;
                        partyTarget.client.Send((byte[])spkt2);
                    }
                }
            }
            //CATCH ALL UNKNOWN ERRORS
            catch (Exception e)
            {
                SMSG_NPCDROPLISTRESULT spkt = new SMSG_NPCDROPLISTRESULT();
                spkt.ActorID   = cpkt.ActorID;
                spkt.Result    = 5;
                spkt.SessionId = this.character.id;
                this.Send((byte[])spkt);
                Console.WriteLine(e);
            }
        }