Exemplo n.º 1
0
        public BattleReward Reward(IBattleEntity victim)
        {
            MonsterBattleEntity monster = victim as MonsterBattleEntity;

            if (monster == null)
            {
                return(null);
            }

            context.GetModule <PlayerModule>().AddExperience(user.Service, user.Name, monster.Monster.Experience);
            context.GetModule <PlayerModule>().UpdateGold(PlayerID, monster.Monster.Gold);

            Item     item     = null;
            DropItem dropitem = monster.Monster.DroppedItems.FirstOrDefault(i => RNG.XORShift64.NextDouble() < i.Rate);

            if (dropitem != null)
            {
                item = context.GetModule <ItemModule>().GetItem(dropitem.ItemID);
                if (item != null)
                {
                    if (context.GetModule <InventoryModule>().AddItem(PlayerID, item.ID, 1) == AddInventoryItemResult.InventoryFull)
                    {
                        item = null;
                    }
                }
            }

            return(new BattleReward {
                XP = monster.Monster.Experience,
                Gold = monster.Monster.Gold,
                Item = item
            });
        }
Exemplo n.º 2
0
        public void MonsterDefeated(MonsterBattleEntity monster, RPGMessageBuilder message)
        {
            IBattleEntity attacker = Actors.FirstOrDefault(a => a is PlayerBattleEntity);

            BattleReward reward = attacker?.Reward(monster);

            if (reward != null)
            {
                message?.BattleActor(attacker).Text(" has killed ").BattleActor(monster).Text(" and receives ").Experience(reward.XP).Text(" and ").Gold(reward.Gold).Text(".");

                if (reward.Item != null)
                {
                    message?.BattleActor(attacker).Text(" finds ").Item(reward.Item).Text(" in the remains.");
                }
            }

            lock (actors)
                actors.Remove(monster);
        }