Inheritance: PolaMUD.MovableEntity, ISerializable
Ejemplo n.º 1
0
        public bool SetNextTurn()
        {
            if (Participants.Count == 1)
            {
                EndBattle();
                return false;
            }

            CurrentTurn = NextTurn;

            if (CurrentTurn is Player)
            {
                CurrentTurn.SendMessage("\n\rBattle! Your turn, action?\n\r", "t=output~txt=Battle! Your turn.\n\r");
                Skill skill;
                int count = 1;
                foreach(SkillInstance skillInstance in CurrentTurn.SkillSlots)
                {
                    skill = skillInstance.Skill;
                    CurrentTurn.SendMessage("- skill" + count + ": " + skill.Name + "\n\r");
                    count++;
                }
            }

            // Currently turn-based combat only supports two participants, the following will need to be changed to support more
            foreach (Mob mob in Participants)
            {
                if (mob != CurrentTurn)
                {
                    NextTurn = mob;
                }
            }

            return true;
        }
Ejemplo n.º 2
0
 public void SelectSkill(Mob target)
 {
     if (target == null)
     {
         target = TargetEnemy;
     }
 }
Ejemplo n.º 3
0
        public static bool CheckValidTarget(Mob attacker, Mob target, TargetType type)
        {
            if (type == TargetType.Enemy)
            {
                if (attacker.Room == null)
                {
                    attacker.TargetEnemy = null;
                    return false;
                }
                if (target == null)
                {
                    attacker.TargetEnemy = null;
                    return false;
                }
                if (target.Room == null)
                {
                    attacker.TargetEnemy = null;
                    target.TargetEnemy = null;
                    return false;
                }

                if (attacker.Room != target.Room)
                {
                    attacker.TargetEnemy = null;
                    target.TargetEnemy = null;
                    return false;
                }

                if (attacker.CombatType == CombatType.TurnBased && target is Player && attacker is Player)
                {
                    attacker.TargetEnemy = null;
                    target.TargetEnemy = null;
                    return false;
                }

                if (attacker.CombatType == CombatType.Realtime && target.CombatType == CombatType.TurnBased)
                {
                    attacker.TargetEnemy = null;
                    target.TargetEnemy = null;
                    return false;
                }

                return true;
                // TODO: This is where we'd add all the safety checks, safe rooms, non-PVP, can't be attacked, etc.
            }
            else if(type == TargetType.Ally)
            {
                return true;
            }

            return false;
        }
Ejemplo n.º 4
0
        public void SetAffect(string name, Mob afflicted, Mob owner, TimerType durationType, int duration, bool tickmethod, bool endmethod)
        {
            Name = name;
            HandlingName = name.ToLower().Trim();
            Duration = duration;
            DurationType = durationType;
            Owner = owner;
            Afflicted = afflicted;
            Level = Owner.Level;

            CanHasTickMethod = tickmethod;
            CanHasEndMethod = endmethod;
        }
Ejemplo n.º 5
0
        // More of this partial class exists at:
        // Communications/Login.cs
        // Communications/Logout.cs
        /// <summary>
        /// Retrieves tshe appropriate Argument from the given input string. 
        /// Argument's reference object is automatically retrieved based on the Type and 
        /// SearchLocations enumeration provided.
        /// </summary>
        /// <param name="line">The input string</param>
        /// <param name="index">The index of the desired argument (1 is always the command itself)</param>
        /// <param name="user">The user Mob, for retrieving references based on this Mob's state</param>
        /// <param name="reference">The Type to search for (Mob, Player, etc.)</param>
        /// <param name="searchLocation">A SearchLocations enumeration to use in finding the reference</param>
        /// <returns></returns>
        public static Argument GetArgument(string line, int index, Mob user, Type reference, int searchLocation)
        {
            Argument argument = GetArgument(line, index);

            argument.Text = argument.Text.ToLower();

            switch (searchLocation)
            {
                case SearchLocations.Room:
                    argument.Reference = ((Room)user.Location).GetEntity(reference, argument.Text);
                    break;
                default:
                    break;
            }

            return argument;
        }
Ejemplo n.º 6
0
        public bool Load(string name)
        {
            XmlDocument document = new XmlDocument();
            XmlNode collection;
            XmlElement element;

            try
            {
                document.Load(name);
            }
            catch
            {
                Global.Error("ERROR: Area '" + name + "' not found.\n");
                return false;
            }

            element = document.DocumentElement;
            Name = element.GetAttribute("name");

            Global.Log("  " + Name + ":\n");

            collection = element["rooms"];
            Room newRoom;
            foreach (XmlNode node in collection.ChildNodes)
            {
                newRoom = new Room(Convert.ToInt32(node.Attributes["index"].Value));
                newRoom.Load(node, this);
                Rooms.Add(newRoom);
            }

            collection = element["mobs"];
            Mob newMob;
            foreach (XmlNode node in collection.ChildNodes)
            {
                newMob = new Mob(node);
            }

            Global.AreaTable.Add(Global.AreaTable.Count, this);
            Global.Log("  " + Name + " loaded, ");

            ForceSpawn();

            Global.Log("spawned\n");

            return true;
        }
Ejemplo n.º 7
0
        public static void AddOrCreateRealtimeBattle(Mob[] mobs)
        {
            RealtimeBattle battle = null;
            foreach (Mob mob in mobs)
            {
                if (mob.Battle != null && mob.Battle is RealtimeBattle)
                    battle = (RealtimeBattle)mob.Battle;
            }

            if (battle == null)
            {
                battle = new RealtimeBattle();
            }

            foreach (Mob mob in mobs)
            {
                if (!battle.Participants.Contains(mob))
                {
                    battle.Participants.Add(mob);
                }
                mob.Battle = battle;
            }
        }
Ejemplo n.º 8
0
        public bool SetTargetAllyAsFirstArg(Mob user, string text)
        {
            Type type = typeof(Mob);
            Argument arg1 = Parser.GetArgument(text, 2, user, type, SearchLocations.Room);
            Mob target = (Mob)arg1.Reference;
            if (target == null)
            {
                if (user.TargetAlly == null)
                {
                    user.SendMessage("They aren't here!\n\r");
                    return false;
                }
                else
                {
                    target = user.TargetAlly;
                }
            }

            if (user.TargetAlly == null)
                user.TargetAlly = target;

            return true;
        }
Ejemplo n.º 9
0
 public void SetTurn(Mob target)
 {
     CurrentTurn = target;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Heal one target notifying the room
        /// </summary>
        /// <param name="healer"></param>
        /// <param name="target"></param>
        /// <param name="skill"></param>
        public static void OneHeal(Mob healer, Mob target, Skill skill)
        {
            if (CheckValidTarget(healer, target, TargetType.Ally) == false)
                return;

            SetTargetAlly(healer, target);

            // if either char is IN battle, we need to add the other to that same battle
            if (healer.Battle != null || target.Battle != null)
            {
                AddOrCreateRealtimeBattle(new Mob[] { healer, target });
            }

            DoHeal(healer, target, GetHeal(healer, target, skill), skill);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Execute one physical combat strike between the attacker and the target,
 /// dealing damage and notifying the room
 /// </summary>
 /// <param name="attacker"></param>
 /// <param name="target"></param>
 public static void OneHit(Mob attacker, Mob target)
 {
     OneHit(attacker, target, Global.SkillTable["Autoattack"]);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Delivers a single message, calling the SendMessage method of all appropriate
        /// Mobs in both the actor's and target's rooms ("appropriate" determined by
        /// messageType).
        /// </summary>
        /// <param name="actor">Mob performing the narrated action (if any!)</param>
        /// <param name="target">Mob receiving the narrated action (if any!)</param>
        /// <param name="messageType">Vector for the message (who it is sent to)</param>
        /// <returns>false if any error conditions are met or any messages fail to send</returns>
        public static bool DeliverMessage(Mob actor, Mob target, MessageVector messageType, String message, String mobileMessage)
        {
            // Early exit conditions
            if (message == null || message.Equals(""))
                return false;
            if (actor == null && target == null)
                return false;
            if (messageType == MessageVector.NotCharacter && actor == null)
                return false;
            if (messageType == MessageVector.NotTarget && target == null)
                return false;

            bool returner = true;

            // Format all of the $ arguments in message
            message = formatMessage(actor, target, message, mobileMessage);

            // Handle the easy ones first: Character & Target;  no need to loop for these.
            if (messageType == MessageVector.Character)
            {
                if (actor == null)
                    return false;

                return actor.SendMessage(message, mobileMessage);
            }
            else if (messageType == MessageVector.Target)
            {
                if (target == null)
                    return false;

                return target.SendMessage(message, mobileMessage);
            }

            // Now we loop through the contents of the room.
            if (actor != null)
            {
                if (((Room)actor.Location) != null && ((Room)actor.Location).Contents != null)
                {
                    foreach (Mob audience in ((Room)actor.Location).Contents)
                    {
                        if (messageType == MessageVector.NotCharacter && audience == actor)
                            continue;
                        if (messageType == MessageVector.NotTarget && audience == target)
                            continue;
                        if (messageType == MessageVector.ThirdParty
                            && (audience == actor || audience == target))
                            continue;

                        if (audience.SendMessage(message, mobileMessage) == false)
                            returner = false;
                    }
                }
                else
                {
                    return false;
                }
            }

            // If the actor is null (for whatever reason) or the target is in a different room, we
            // need to display the message to the appropriate audience in the target's room.
            if (target != null && (actor == null || ((Room)target.Location).IndexNumber != ((Room)actor.Location).IndexNumber))
            {
                if (((Room)target.Location) != null && ((Room)target.Location).Contents != null)
                {
                    foreach (Mob audience in ((Room)target.Location).Contents)
                    {
                        if (messageType == MessageVector.NotCharacter && audience == actor)
                            continue;
                        if (messageType == MessageVector.NotTarget && audience == target)
                            continue;
                        if (messageType == MessageVector.ThirdParty
                            && (audience == actor || audience == target))
                            continue;

                        if (audience.SendMessage(message, mobileMessage) == false)
                            returner = false;
                    }
                }
                else
                {
                    return false;
                }
            }

            return returner;
        }
Ejemplo n.º 13
0
        public static void OneHit(Mob attacker, Mob target, Skill skill, int dam)
        {
            if (CheckValidTarget(attacker, target) == false)
                return;

            if (attacker.Battle == null || attacker.Battle is RealtimeBattle)
                StartRealtimeCombat(attacker, target);
            else if (attacker.Battle == null || attacker.Battle is TurnBattle)
                StartTurnCombat(attacker, target);

            DoOneHit(attacker, target, skill, dam);
        }
Ejemplo n.º 14
0
        public bool CommandDb(Player user, Command command, string text)
        {
            if (Parser.GetArgument(text, 2).Text == "entities")
            {
                if (Parser.GetArgument(text, 3).Text == "list")
                {
                    int count = 1;
                    foreach (Entity thing in Global.Entites)
                    {
                        user.SendMessage(count + ".  " + "[" + thing.Name + "] #" + thing.IndexNumber + "; type: " + thing.GetType() + "\n\r");
                        count++;
                    }
                }
            }
            if (Parser.GetArgument(text, 2).Text == "menu")
            {
                DynamicMenu menu = new DynamicMenu(user, "HandleMenu");
                menu.List.Add("waffle", new Command("waffle", "", false, "Menu item 1"));
                menu.List.Add("carrot", new Command("carrot", "", false, "Menu item 2"));
                menu.List.Add("apple", new Command("apple", "", false, "Menu item 3"));
                user.Menu = menu;
                user.SendMessage("Please select from the following: waffle, carrot, apple\n\r");
            }
            if (Parser.GetArgument(text, 2).Text == "littleman")
            {
                AreaLittleMan littleMan = new AreaLittleMan(300, 7);
                Area area = littleMan.Generate();
                Room room = area.Rooms[0];
                Instance instance = InstanceManager.NewInstance(user, Convert.ToInt32(Parser.GetArgument(text, 3).Text));
                instance.Area = area;
                user.Move(room);
            }
            if (Parser.GetArgument(text, 2).Text == "map")
            {
                Area area = ((Room)user.Location).Area;

            }
            if (Parser.GetArgument(text, 2).Text == "instance")
            {
                InstanceManager.NewInstance(user, Convert.ToInt32(Parser.GetArgument(text, 3).Text));

            }
            if (Parser.GetArgument(text, 2).Text == "killinstance")
            {
                InstanceManager.RemoveInstance(user);
            }
            if (Parser.GetArgument(text, 2).Text == "bat")
            {
                Mob mob = new Mob();
                mob.Name = "test mob #" + Combat.Random.Next(0, 9);
                mob.Skills.Add("Autoattack", new SkillInstance(Global.SkillTable["Autoattack"], new SkillAI()));
            }

            return true;
        }
Ejemplo n.º 15
0
        public static void Kill(Mob attacker, Mob target)
        {
            Communications.DeliverMessage
                (target, null, MessageVector.Character, "\n\r\n\rYou are " + Colors.BRIGHT_RED + "DEAD!!" + Colors.CLEAR + "\n\r\n\r", "");
            Communications.DeliverMessage
                (target, null, MessageVector.ThirdParty, "$n is " + Colors.BRIGHT_RED + "DEAD!!" + Colors.CLEAR + "\n\r", "");

            if (target is Player)
            {
                //reward

                //clean up
                attacker.TargetEnemy = null;
                target.TargetEnemy = null;

                if (target.CombatType == CombatType.TurnBased)
                {
                    target.Battle.Participants.Remove(target);
                    target.Menu = null;
                    attacker.Menu = null;
                }

                target.Battle = null;
                attacker.Battle = null;
                target.Move(Global.RoomTable[101]);
                target.Restore();

                target.WaitPulses = Global.RoundDuration * 5;
            }
            else if (target is Mob)
            {
                //reward
                attacker.RewardExperience(target.ExperienceReward);
                attacker.AddCoins(target.Coins);

                //clean up
                attacker.TargetEnemy = null;
                target.TargetEnemy = null;

                if (target.CombatType == CombatType.TurnBased)
                {
                    target.Battle.Participants.Remove(target);
                    target.Menu = null;
                    attacker.Menu = null;
                }

                target.Battle = null;
                attacker.Battle = null;
                target.Delete();
            }
        }
Ejemplo n.º 16
0
        public static void StartRealtimeCombat(Mob attacker, Mob target)
        {
            if (CheckValidTarget(attacker, target) == false)
                return;

            SetTargetEnemies(attacker, target);

            AddOrCreateRealtimeBattle(new Mob[] { attacker, target });
        }
Ejemplo n.º 17
0
        public static void StartTurnCombat(Mob attacker, Mob target)
        {
            if (attacker.Battle != null && target.Battle != null)
                return;

            if (CheckValidTarget(attacker, target) == false)
                return;

            SetTargetEnemies(attacker, target);

            attacker.CombatType = CombatType.TurnBased;
            target.CombatType = CombatType.TurnBased;

            TurnBattle battle = new TurnBattle();
            battle.Participants.Add(attacker);
            battle.Participants.Add(target);
            battle.NextTurn = attacker;
            battle.CurrentTurn = target;

            attacker.Battle = battle;
            target.Battle = battle;

            battle.SetNextTurn();
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Use to ensure that the mobs are both targeting each other if they don't currently have targets.
 /// </summary>
 /// <param name="mob1"></param>
 /// <param name="mob2"></param>
 public static void SetTargetEnemies(Mob mob1, Mob mob2)
 {
     if (mob1.TargetEnemy == null)
         mob1.TargetEnemy = mob2;
     if (mob2.TargetEnemy == null)
         mob2.TargetEnemy = mob1;
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Use to ensure that the mobs are both targeting each other if they don't currently have targets.
 /// </summary>
 /// <param name="mob1"></param>
 /// <param name="mob2"></param>
 public static void SetTargetAlly(Mob mob1, Mob mob2)
 {
     mob1.TargetAlly = mob2;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Check if one mob can successfully attack the other
 /// </summary>
 /// <param name="attacker"></param>
 /// <param name="target"></param>
 /// <returns></returns>
 public static bool CheckValidTarget(Mob attacker, Mob target)
 {
     return CheckValidTarget(attacker, target, TargetType.Enemy);
 }
Ejemplo n.º 21
0
 public static void MultiHit(Mob attacker, Mob target)
 {
     OneHit(attacker, target);
     OneHit(attacker, target);
 }
Ejemplo n.º 22
0
 public static void Heal(Mob attacker, Mob target, int heal)
 {
     target.Health += heal;
 }
Ejemplo n.º 23
0
        public static int LevelModifier(Mob user, bool attack)
        {
            int modifierPercent = 100;

            if (attack == true)
            {
                modifierPercent = user.Level * 3 + 100;
            }

            return modifierPercent;
        }
Ejemplo n.º 24
0
 /// <summary>
 /// This is executed at a specific time based on the PreLag and PostLag variables
 /// </summary>
 /// <param name="user"></param>
 /// <param name="text"></param>
 /// <returns></returns>
 public virtual bool Action(Mob user, string text)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Formats any $ arguments contained within a message string.
        /// </summary>
        /// <param name="actor">Mob performing the action</param>
        /// <param name="target">Mob receiving the action</param>
        /// <param name="message">Message string to format</param>
        public static String formatMessage(Mob actor, Mob target, String message, String mobileMessage)
        {
            StringBuilder buffer = new StringBuilder();
            String[] he = { "he", "it", "she" };
            String[] him = { "him", "it", "her" };
            String[] his = { "his", "its", "hers" };

            int index = 0;

            for (int c = 0; c < message.Length; c++)
            {
                if (message[c] == '$')
                {
                    if (c != 0)
                    {
                        buffer.Append(message.Substring(index, (c - index)));
                        index = c;
                    }

                    if (message.Length >= c+1)
                    {
                        switch (message[c + 1])
                        {
                            case 'e':
                                if (actor != null)
                                    buffer.Append(he[(int)(actor.Gender)]);
                                c++;
                                index = c+1;
                                break;
                            case 'E':
                                if (target != null)
                                    buffer.Append(he[(int)(target.Gender)]);
                                c++;
                                index = c+1;
                                break;
                            case 's':
                                if (actor != null)
                                    buffer.Append(his[(int)(actor.Gender)]);
                                c++;
                                index = c+1;
                                break;
                            case 'S':
                                if (target != null)
                                    buffer.Append(his[(int)(target.Gender)]);
                                c++;
                                index = c+1;
                                break;
                            case 'm':
                                if (actor != null)
                                    buffer.Append(him[(int)(actor.Gender)]);
                                c++;
                                index = c+1;
                                break;
                            case 'M':
                                if (target != null)
                                    buffer.Append(him[(int)(target.Gender)]);
                                c++;
                                index = c+1;
                                break;
                            case 'n':
                                if (actor != null)
                                    buffer.Append(actor.Name);
                                c++;
                                index = c+1;
                                break;
                            case 'N':
                                if (target != null)
                                    buffer.Append(target.Name);
                                c++;
                                index = c+1;
                                break;
                            // TODO:  Not sure what to do with these just yet.
                            case 't':
                                break;
                            case 'T':
                                break;
                            case 'p':
                                break;
                            case 'P':
                                break;
                            case '$':
                                buffer.Append('$');
                                c++;
                                index = c+1;
                                break;
                            default:
                                buffer.Append('$');
                                break;
                        }
                    }
                }
            }
            buffer.Append(message.Substring(index));

            return buffer.ToString();
        }
Ejemplo n.º 26
0
 /// <summary>
 /// This is executed at the very moment the user uses the ability
 /// </summary>
 /// <param name="user"></param>
 /// <param name="text"></param>
 /// <returns></returns>
 public virtual bool PreAction(Mob user, string text)
 {
     return true;
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Narrates a single action, calling the DeliverMessage method for
        /// MessageVectors Character, Target, and Third_Party.  This can be
        /// used if the message does not change at all between these three calls,
        /// save for the arguments of who-receives-what.
        /// 
        /// Maybe. :D
        /// 
        /// Work in progress.
        /// </summary>
        /// <param name="actor"></param>
        /// <param name="target"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static bool NarrateAction(Mob actor, Mob target, String message, String mobileMessage)
        {
            bool returner = true;
            if (DeliverMessage(actor, target, MessageVector.Character, message, mobileMessage) == false)
                returner = false;
            if (DeliverMessage(actor, target, MessageVector.Target, message, mobileMessage) == false)
                returner = false;
            if (DeliverMessage(actor, target, MessageVector.ThirdParty, message, mobileMessage) == false)
                returner = false;

            return returner;
        }
Ejemplo n.º 28
0
 public static void OneHit(Mob attacker, Mob target, Skill skill)
 {
     OneHit(attacker, target, skill, GetOneHit(attacker, target, skill));
 }
Ejemplo n.º 29
0
 public override void Spawn()
 {
     Mob mob = new Mob(IndexNumber);
     mob.Move(Room);
 }
Ejemplo n.º 30
0
 public void DecrementAffects(Mob mob, TimerType type)
 {
     List<Affect> ToRemove = new List<Affect>();
     foreach (Affect affect in mob.Affects)
     {
         if (affect.DurationType == type)
             if (affect.Decrement() == 0)
                 ToRemove.Add(affect);
     }
     foreach (Affect affect in ToRemove)
     {
         mob.Affects.Remove(affect);
     }
 }