Ejemplo n.º 1
0
 public static CombatResolver CreateSource(BattleEntity entity, CombatRound round)
 {
     return entity.CreateCombatNodeBuilder()
         .SetSkillCombatNode(round)
         .SetWeaponIndex(round.weaponIndex)
         .BuildResolver();
 }
Ejemplo n.º 2
0
        private CombatRound DoMobHits()
        {
            //Console.WriteLine("Enter DoMobHits");
            var round = new CombatRound();

            try
            {
                // mob hits first
                foreach (var npc in mobs)
                {
                    // only attempt to hit if there are players left to hit
                    if (fighters.Any(p => p.HitPoints > 0))
                    {
                        // choose player to hit at random, and hit
                        var playerToHit = fighters
                                          .Where(p => p.HitPoints > 0)
                                          .OrderBy(x => Guid.NewGuid()).FirstOrDefault();

                        round += npc.Hit(playerToHit); // queues "mob hit you" and "mob hit <player>" text

                        if (playerToHit.HitPoints <= 0)
                        {
                            playerToHit.Die(); // changes status

                            var statusText = Player.GetStatusText(playerToHit.Status).ToUpper();

                            var playerText = string.Format("You are {0}!!!", statusText);
                            if (playerToHit.HitPoints < Server.DeadHitPoints)
                            {
                                playerText += " You have respawned, but you're in a different location.\n" +
                                              "Your corpse will remain for a short while, but you'll want to retrieve your\n" +
                                              "items in short order.";
                            }

                            var groupText = string.Format("{0} is {1}!!!", playerToHit.Forename, statusText);

                            round.AddText(playerToHit, playerText, CombatTextType.Player);
                            round.AddText(playerToHit, groupText, CombatTextType.Group);
                            round.AddText(playerToHit, groupText, CombatTextType.Room);

                            RemoveFromCombat(playerToHit);
                            removeFromCombatLater.Add(playerToHit);

                            if (fighters.Count == 0)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(round);
        }
Ejemplo n.º 3
0
    private static void AddHitChanceStatusEffectRules(CombatOperation.Builder builder, HitChanceLogic hitChance, CombatRound combatRound)
    {
        if(combatRound.statusEffectRules == null) {
            return;
        }

        foreach(StatusEffectRule rule in combatRound.statusEffectRules) {
        //	builder.AddLogic(
        }
    }
        /// <summary>
        /// Called when the add take turn topic is started
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public Task <bool> StartTopic(BotContext context)
        {
            CombatRound = new CombatRound()
            {
                // Initialize fresh set of moves
                combatActions = CombatRound.CombatActions.Move | CombatRound.CombatActions.Standard | CombatRound.CombatActions.Swift | CombatRound.CombatActions.DoubleMove
            };

            return(PromptForNextMove(context));
        }
Ejemplo n.º 5
0
        private CombatRound DoPlayerHits()
        {
            //Console.WriteLine("Enter DoPlayerHits");
            var round = new CombatRound();

            try
            {
                var killedBy = new Dictionary <NonPlayer, Player>();

                // if still players, they hit
                foreach (var player in fighters)
                {
                    if (mobs.Any(m => m.HitPoints > 0))
                    {
                        var mobToHit = mobs
                                       .Where(m => m.HitPoints > 0)
                                       .OrderBy(x => Guid.NewGuid()).FirstOrDefault();

                        round += player.Hit(mobToHit);

                        // check for killing blow, could be multiple
                        if (mobToHit.HitPoints <= 0)
                        {
                            killedBy.Add(mobToHit, player);
                            // remove mob from combat, so it can't be hit any more
                            RemoveFromCombat(mobToHit);
                            round += mobToHit.Die();
                            if (mobs.Count == 0)
                            {
                                break; // stop fighting
                            }
                        }
                    }
                }

                if (killedBy.Count > 0)
                {
                    foreach (var kb in killedBy)
                    {
                        round.AddText(kb.Value, string.Format("`R{0} is DEAD!!!\n", kb.Key.Name), CombatTextType.KillingBlow);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(round);
        }
Ejemplo n.º 6
0
        internal void Round(long combatTickRate)
        {
            var roundText = new CombatRound();

            if (isAggro)
            {
                roundText += DoMobHits();

                roundText += DoPlayerHits();
            }
            else
            {
                roundText += DoPlayerHits();

                roundText += DoMobHits();
            }

            roundText.Print(combatOrder);

            foreach (var removing in removeFromCombatLater)
            {
                combatOrder.Remove(removing);
            }

            // send text to room
            room.SendPlayers(roundText.GetRoomText(), null, null, fightersToIgnore.ToArray());

            // no longer ignore incapacitated players
            foreach (var removing in removeFromCombatLater)
            {
                fightersToIgnore.Remove(removing);

                if (removing.HitPoints < Server.DeadHitPoints)
                {
                    removing.DieForReal();
                }
            }

            // reset each round
            removeFromCombatLater.Clear();

            Thread.Sleep((int)combatTickRate);
        }
Ejemplo n.º 7
0
    public static ICombatOperation createOperation(BattleEntity src, BattleEntity dest, CombatRound combatRound)
    {
        CombatResolver srcRes = CombatResolverFactory.CreateSource(src, combatRound);
        CombatResolver destRes = CombatResolverFactory.CreateDestination(dest);

        HitChanceLogic hitChanceLogic = new HitChanceLogic ();
        DamageLogic damageLogic = new DamageLogic ();

        CombatOperation.Builder builder = new CombatOperation.Builder ();
        builder.AddLogic(damageLogic)
            .Require(delegate(ICombatLogic [] conditions) {
                    HitChanceLogic hitChance = (HitChanceLogic) conditions[0];
                    return hitChance.Hits;
            }, hitChanceLogic);

        AddHitChanceStatusEffectRules(builder, hitChanceLogic, combatRound);

        return builder.Build(srcRes, destRes);
    }
Ejemplo n.º 8
0
        public virtual int Resolve(string ThisFighterId)
        {
            int ret = 0;

            //string opponentFighterId = otherFighterId(ThisFighterId);
            string opponentFighterId = CombatHelpers.otherFighterId(ThisFighterId, _combatSession);

            if (_combatSession.CombatRounds.Where(x => x.Result != null).Count() == 0)
            {
                return(0);
            }

            for (int i = _combatSession.CombatRounds.Count - 1; i > -1; i--)
            {
                CombatRound combatRound = _combatSession.CombatRounds[i];

                if (combatRound.Result != null)
                {
                    //if (combatRound.Moves.Where(x => x.FighterId == ThisFighterId).FirstOrDefault().Action == CombatEnums.SWING &&
                    //    combatRound.Moves.Where(x => x.FighterId == opponentFighterId).FirstOrDefault().Action == CombatEnums.REST
                    //)
                    if (truthCondition
                        (
                            combatRound.Moves.Where(x => x.FighterId == ThisFighterId).FirstOrDefault().Action,
                            combatRound.Moves.Where(x => x.FighterId == opponentFighterId).FirstOrDefault().Action
                        )
                        )
                    {
                        ret++;
                    }
                    else
                    {
                        return(ret);
                    }
                }
            }

            return(ret);
        }
Ejemplo n.º 9
0
        public CombatRound Hit(NonPlayer mob)
        {
            var round = new CombatRound();

            if (Server.Current.Random.Next(HitRoll) + 1 >= mob.Armor)
            {
                // hit
                var damage = Server.Current.Random.Next(DamRoll) + 1;
                mob.HitPoints -= damage;

                // apply experience
                ExperienceResolver.ApplyExperience(this, damage);

                var damageAction = CombatHelper.GetDamageAction(mob, damage);

                // player text
                var playerText = string.Format("You {0} {1} for {2} damage!\n", damageAction.Singular, mob.Name, damage);
                round.AddText(this, playerText, CombatTextType.Player);

                // group text (excludes player)
                var groupText = string.Format("{0} {1} {2}!\n", Forename, damageAction.Plural, mob.Name);
                round.AddText(this, groupText, CombatTextType.Group);
            }
            else
            {
                var playerText = string.Format("You miss {0}!\n", mob.Name);
                round.AddText(this, playerText, CombatTextType.Player);

                var groupText = string.Format("{0} misses {1}!\n", Forename, mob.Name);
                round.AddText(this, groupText, CombatTextType.Group);
            }

            // finally set some generic room text
            round.AddText(null, string.Format("{0} is fighting {1}!\n", Forename, mob.Name), CombatTextType.Room);

            return(round);
        }
Ejemplo n.º 10
0
        public CombatRound Hit(Player player)
        {
            var round = new CombatRound();

            // roll to hit, if success, then hit
            if (Server.Current.Random.Next(HitRoll) + 1 >= player.Armor)
            {
                // hit
                var damage = Server.Current.Random.Next(DamRoll) + 1;
                player.HitPoints -= damage;

                var damageAction = CombatHelper.GetDamageAction(player, damage);

                var playerText = string.Format("{0} {1} you for {2} damage!\n", Name, damageAction.Plural, damage);
                round.AddText(player, playerText, CombatTextType.Player);

                var groupText = string.Format("{0} {1} {2}!\n", Name, damageAction.Plural, player.Forename);
                round.AddText(player, groupText, CombatTextType.Group);
            }
            else
            {
                // miss
                var playerText = string.Format("{0} misses you!", Name);
                round.AddText(player, playerText, CombatTextType.Player);

                var groupText = string.Format("{0} misses {1}!\n", Name, player.Forename);
                round.AddText(player, groupText, CombatTextType.Group);
            }

            if (!_skillLoopStarted && Skills.Count > 0)
            {
                doSkillLoop(null, null);
            }

            return(round);
        }
Ejemplo n.º 11
0
        public CombatRound Die(bool shutdown = false)
        {
            var round = new CombatRound();

            if (!shutdown)
            {
                // create a corpse item with .ContainsItems equal to whatever was held/equipped
                var corpseTemplate = Server.Current.Database.Get <Template>("corpse");
                var dupedCorpse    = Mapper.Map <PlayerItem>(corpseTemplate);
                foreach (var item in Inventory
                         .Select(i => new KeyValuePair <string, string>(i.Key, i.Value))
                         .Union(Equipped.Values.Select(e => new KeyValuePair <string, string>(e.Key, e.Name))))
                {
                    var corpseItem = Server.Current.Database.Get <PlayerItem>(item.Key);
                    dupedCorpse.ContainedItems[corpseItem.Key] = corpseItem.Name;
                }

                dupedCorpse.Name        = string.Format("The corpse of {0}", Name);
                dupedCorpse.Description = string.Format("The corpse of {0}", Name.ToLower());
                dupedCorpse.Keywords    = new List <string>()
                {
                    "corpse", Name
                }.ToArray();
                dupedCorpse.WearLocation = Wearlocation.Corpse;
                dupedCorpse.Gold         = getRandomGold(Gold);

                // put corpse in room
                var room = RoomHelper.GetPlayerRoom(Location);
                room.AddItem(dupedCorpse);
                Console.WriteLine("NEW CORPSE: {0}", dupedCorpse.Key);
                room.CorpseQueue[dupedCorpse.Key] = DateTime.Now.AddMilliseconds(Server.CorpseDecayTime);

                // must cache since we're not saving
                Server.Current.Database.Put(dupedCorpse);

                // delete mob
                room.RemoveNpc(this);
                Server.Current.Database.Delete <NonPlayer>(Key);

                round.AddText(null, string.Format("`R{0} is DEAD!!!", Name), CombatTextType.Room);

                // get area from this.RespawnRoom
                var area = Server.Current.Areas.FirstOrDefault(a => a.Key == room.Area);

                // add to .RepopQueue
                area.RepopQueue.Add(MobTemplateKey);
            }
            else
            {
                // delete inventory/equipped items' .db files
                foreach (var key in Inventory.Keys.Union(Equipped.Values.Select(e => e.Key)))
                {
                    ItemHelper.DeleteItem(key);
                }
            }

            // delete .db file
            Server.Current.Database.Delete <NonPlayer>(Key);

            return(round);
        }
Ejemplo n.º 12
0
 public CombatNodeBuilder SetSkillCombatNode(CombatRound round)
 {
     mSkillCombatNode = new SkillCombatNode(round);
     return this;
 }
Ejemplo n.º 13
0
 public void nextCombat()
 {
     currentCombatRound = new CombatRound(roundTime / 2, damage, playerHealth, enemyHealth);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Creates a new instance that just keeps track of some of the meta data.
 /// The skill itself should generate its own statistics because it can vary from
 /// skill level which isnt put into place.
 /// </summary>
 /// <param name="skillOrigin">Skill origin.</param>
 public SkillCombatNode(CombatRound round)
     : base()
 {
     Load (round.combatProperties);
 }