Beispiel #1
0
        /// <summary>
        /// Execute the specified command.
        /// </summary>
        /// <param name="world">A reference to the game world.</param>
        /// <param name="gameMap">A reference to the game map.</param>
        /// <param name="msg">The creature's message.</param>
        public static void ExecuteCommand(GameWorld world, Map gameMap,
            string msg, Creature creature)
        {
            string[] parameters = Regex.Split(msg, " ");

            commands[parameters[0].ToLower()].CommandMethod.
                Invoke(new object[] { world, gameMap, parameters, creature });
        }
Beispiel #2
0
 /// <summary>
 /// Adds a creature to a single tile with only the 
 /// most basic information. Note: Used for speeding up
 /// loading spawns.
 /// </summary>
 /// <param name="creature">Creature to add.</param>
 /// <param name="position">Position to add creature.</param>
 public void AddCachedCreature(Creature creature, Position position)
 {
     lock (lockThis) {
         creature.World = this;
         creaturesOnline.Add(creature.GetID(), creature);
         creature.Finder = pathFinder;
         creature.LogedIn = true;
         gameMap.AddThing(creature, position);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Sends a private message to another player.
 /// </summary>
 /// <param name="sender">The creature sending.</param>
 /// <param name="recipient">The recipient's name (player).</param>
 /// <param name="msg">The message to send.</param>
 private void AppendPrivateMessage(Creature sender, string recipient, string msg)
 {
     recipient = recipient.ToLower();
     foreach (KeyValuePair<string, Player> kvp in playersOnline) {
         if (kvp.Key.StartsWith(recipient)) {
             kvp.Value.AddGlobalChat(ChatGlobal.PRIVATE_MSG, msg, sender.Name);
             sender.AddStatusMessage("Message sent to " + kvp.Value.Name + ".");
             return;
         }
     }
     sender.AddStatusMessage("A player with this name is not online.");
 }
Beispiel #4
0
 /// <summary>
 /// Handle a message from a creature.
 /// </summary>
 /// <param name="creature">The creature sending the message.</param>
 /// <param name="msg">The message sent.</param>
 public void HandleChat(Creature creature, string msg)
 {
     ThingSet tSet = new ThingSet();
     if (msg.StartsWith(PRIVATE_MSG_INDICATOR)) {
         HandlePrivateMessage(creature, msg);
     } else if (msg.StartsWith(MSG_QUANTIFIER)) {
         HandleQuantifiedMessage(creature, msg, tSet);
     } else {
         tSet = gameMap.GetThingsInVicinity(creature.CurrentPosition, true);
         HandleLocalChat(creature.GetChatType(), tSet, msg, creature);
     }
 }
Beispiel #5
0
 /// <summary>
 /// Gets whether this message is a command. Note: Returns true
 /// only if it is a command and the creature has a high
 /// enough access level.
 /// </summary>
 /// <param name="msg">The message to test</param>
 /// <param name="creature">The creature for whom to test</param>
 /// <returns>True if it is a command and creature has valid access
 /// or false otherwise</returns>
 public static bool IsCommand(string msg, Creature creature)
 {
     string[] parameters = Regex.Split(msg, " ");
     if (parameters.Length == 0) {
         return false;
     }
     string command = parameters[0];
     if (!commands.ContainsKey(command.ToLower())) {
         return false;
     }
     return true; //TODO: Uncomment the bottom command
     //            return creature.Access >= commands[command.ToLower()].AccessLevel;
 }
Beispiel #6
0
 /// <summary>
 /// Handles sending a chat message in a player's local vicinity.
 /// </summary>
 /// <param name="type">The type of chat to send.</param>
 /// <param name="set">The set of things in the player's local vicinity.</param>
 /// <param name="msg">The message to send.</param>
 /// <param name="sender">The sender of the message.</param>
 private void HandleLocalChat(ChatLocal type, ThingSet set, 
     string msg, Creature sender)
 {
     foreach (Thing thing in set.GetThings()) {
         thing.AddLocalChat(type, msg, sender.CurrentPosition, sender);
     }
 }
Beispiel #7
0
        /// <summary>
        /// Use this method cast the specified spell. Note: This method only
        /// appends and does not send protocol data.
        /// </summary>
        /// <param name="caster">The creature casting the spell</param>
        /// <param name="spell">The spell to cast</param>
        /// <param name="tSet">The set of affected things</param>
        public void CastSpell(string msg, Creature caster, Spell spell, GameWorld world)
        {
            /*string error = caster.CanCastSpell(spell);
            if (error != null) {
                caster.AddAnonymousChat(ChatAnonymous.WHITE, error);
                return;
            }*/ //TODO: Uncomment

            if (spell.IsSpellValid != null && !spell.IsSpellValid(world, msg)) {
                world.AddMagicEffect(MagicEffect.PUFF, caster.CurrentPosition);
                return;
            }
            if (spell.RequiresTarget) {
                Tile tile = map.GetTile(spell.SpellCenter);
                if (tile == null || !tile.ContainsType(Constants.TYPE_CREATURE)) {
                    world.AddMagicEffect(MagicEffect.PUFF, caster.CurrentPosition);
                    caster.AddAnonymousChat(ChatAnonymous.WHITE, "No target selected.");
                    return;
                }
            }
            //Constants.
            //Not the most efficient method but it is simple and works.
            int length = spell.SpellArea.GetLength(0);
            int width = spell.SpellArea.GetLength(1);

            Position startPos = new Position();
            startPos.x = (ushort)(spell.SpellCenter.x - (width / 2));
            startPos.y = (ushort)(spell.SpellCenter.y - (length / 2));
            startPos.z = spell.SpellCenter.z;
            Position local = new Position();

            List<Thing> things = new List<Thing>();
            for (int i = 0; i < length; i++) {
                for (int j = 0; j < width; j++) {
                    local.x = (ushort)(startPos.x + j);
                    local.y = (ushort)(startPos.y + i);
                    local.z = startPos.z;
                    if (map.GetTile(local) == null
                        /*|| !map.GetTile(local).CanMoveTo(caster)
                         * TODO: Finish*/) {
                        continue;
                    }

                    if (spell.SpellArea[i, j] &&
                        !map.GetTile(local).ContainsType(Constants.TYPE_BLOCKS_MAGIC)) {
                        ThingSet tSet = map.GetThingsInVicinity(local);
                        foreach (Thing thing in tSet.GetThings()) {
                            thing.AddEffect(spell.SpellEffect, local);
                            if (spell.HasDistanceType()) {
                                thing.AddShootEffect((byte)spell.DistanceEffect,
                                    caster.CurrentPosition, spell.SpellCenter);
                            }
                        }

                        List<Thing> localThings = map.GetTile(local).GetThings();

                        if (spell.Action != null) {
                            spell.Action.Invoke(world, local, localThings);
                        }

                        foreach (Thing thing in map.GetTile(local).GetThings()) {
                            things.Add(thing);
                        }
                    }
                }
            }

            foreach (Thing thing in things) {
                thing.AppendHandleDamage(spell.GetDamage(), caster, spell.Immunity, world, true);
            }

            //caster.NotifyOfSuccessfulCast(spell); TODO: Uncomment
        }
Beispiel #8
0
        public void TurnTowardsTarget(Creature target)
        {
            //basic error checks
            if (target == null)
                return;

            //Here comes the formula :D
            Position oppPos = target.CurrentPosition;
            Position thisPos = this.CurrentPosition;

            Direction directionToTurn = Direction.WEST;

            if (oppPos.x < thisPos.x) {
                directionToTurn = Direction.WEST;
            } else if (oppPos.x > thisPos.x) {
                directionToTurn = Direction.EAST;
            } else if (oppPos.y < thisPos.y) {
                directionToTurn = Direction.NORTH;
            } else if (oppPos.y > thisPos.y) {
                directionToTurn = Direction.SOUTH;
            }

            if (CurrentDirection == directionToTurn) {
                //Already facing this direction...
                return;
            }

            World.HandleChangeDirection(this, directionToTurn);
        }
Beispiel #9
0
        /// <summary>
        /// Gets how much damage to be done to this creature based on
        /// the attacking creature's stats.
        /// </summary>
        /// <param name="attacker">The creature attacking.</param>
        /// <returns>The damage amount if > 0 or PUFF/SPARK constants 
        /// otherwise.</returns>
        public int GetDamageAmt(Creature attacker)
        {
            int atkValue = attacker.GetAtkValue();
            int shieldValue = this.GetShieldValue();
            int netValue = atkValue - shieldValue;

            if (netValue > 0) {
                return netValue;
            } else if (netValue == 0) {
                return Constants.SPARK;
            } else {
                return Constants.PUFF;
            }
        }
Beispiel #10
0
 public abstract void UpdateCreatureLight(Creature creature, byte light);
Beispiel #11
0
 public AttackersInformation(Creature atker, int amtDealt)
 {
     Attacker = atker;
     DamageByCreature = amtDealt;
 }
Beispiel #12
0
 public abstract void AddScreenCreature(Creature creature, bool knowsCreature,
     Position pos, byte stackpos);
Beispiel #13
0
 public abstract void AddTileCreature(Creature creature, bool knowsCreature);
Beispiel #14
0
 public abstract void AddRequestOutfit(Creature creature);
Beispiel #15
0
 public abstract void AddCreatureMove(Direction direction, Creature creature,
     Position oldPos, Position newPos, byte oldStackpos, byte newStackpos);
Beispiel #16
0
 public abstract void UpdateCreatureOutfit(Creature creature);
Beispiel #17
0
        /// <summary>
        /// This method handles a private message.
        /// </summary>
        /// <param name="sender">The sender of the message.</param>
        /// <param name="msg">The message itself.</param>
        private void HandlePrivateMessage(Creature sender, string msg)
        {
            // Valid format: *name* msg

            if (!msg.StartsWith(PRIVATE_MSG_INDICATOR)) {
                throw new Exception("Invalid call to HandlePrivateMessage()");
            }

            bool isName = true;
            string name = "";
            string message = "";
            for (int i = 1; i < msg.Length; i++) {
                string charAt = msg[i] + "";
                if (charAt == PRIVATE_MSG_INDICATOR) {
                    isName = false;
                    continue; //Skip adding PRIVATE_MSG_INDICATOR to message
                }

                if (isName) {
                    name += charAt;
                } else {
                    message += charAt;
                }
            }

            //Remove starting space, if applicable;
            if (message.StartsWith(EMPTY_SPACE)) {
            #if DEBUG
                Log.WriteDebug("Message started with empty space.");
            #endif
                message = message.Substring(1);
            }

            AppendPrivateMessage(sender, name, message);
        }
Beispiel #18
0
        /// <summary>
        /// Handles a broadcast made by a creature.
        /// </summary>
        /// <param name="sender">The sender of the broadcast.</param>
        /// <param name="msg">The message to broadcast.</param>
        private void HandleBroadcast(Creature sender, string msg)
        {
            if (!msg.ToLower().StartsWith(BROADCAST_TYPE + "")) {
                throw new Exception("Invalid call to HandleBroadcast()");
            }
            msg = msg.Substring(1); //Remove quantifier type

            //Invalid access level
            if (sender.Access < Constants.ACCESS_GAMEMASTER) {
                return;
            }

            foreach (KeyValuePair<string, Player> kvp in playersOnline) {
                kvp.Value.ResetNetMessages();
                kvp.Value.AddGlobalChat(ChatGlobal.BROADCAST, msg, sender.Name);
                kvp.Value.WriteToSocket();
            }
        }
Beispiel #19
0
        /// <summary>
        /// A quantified message is a message that starts with a special character. For example,
        /// in tibia 6.4, # is a quantifier, so #y is used to yell, #w is used to whisper etc.
        /// </summary>
        /// <param name="sender">Sender of the quantified message.</param>
        /// <param name="msg">The message itself.</param>
        private void HandleQuantifiedMessage(Creature sender, string msg, ThingSet tSet)
        {
            if (!msg.StartsWith(MSG_QUANTIFIER)) {
                throw new Exception("Invalid call to HandleQuantifiedMessage()");
            }
            msg = msg.Substring(1); //Remove first quanitifer
            char quantifierType = char.ToLower(msg[0]);
            switch (quantifierType) {
                case BROADCAST_TYPE:
                    HandleBroadcast(sender, msg);
                    break;
                case WHISPER_TYPE:
                     gameMap.GetThingsInWhisperVicinity(sender.CurrentPosition, tSet);
                    //msg.Substring(2) is called in order to remove quantifier type and a space
                     HandleLocalChat(ChatLocal.WHISPER, tSet, msg.Substring(2), sender);

                    break;
                case YELL_TYPE:
                    gameMap.GetThingsInYellVacinity(sender.CurrentPosition, tSet);
                    //msg.Substring(2) is called in order to remove quantifier type and a space
                    HandleLocalChat(ChatLocal.YELLS, tSet, msg.Substring(2).ToUpper(), sender);
                    break;
                default:
            #if DEBUG
                    Log.WriteDebug("Invalid quantifier type");
            #endif
                    break;
            }
        }
Beispiel #20
0
 public override void AppendHandleDamage(int dmgAmt, Creature attacker, ImmunityType type,
     GameWorld world, bool magic)
 {
     world.AppendAddDamage(attacker, this, dmgAmt, type, magic);
 }
Beispiel #21
0
 public override void AddCreatureMove(Direction direction, Creature creature,
     Position oldPos, Position newPos, byte oldStackpos, byte newStackpos)
 {
     if (!creature.AttackableByMonster()) {
         return;
     }
     potentialTargets.Add(creature);
     PerformThink();
 }
Beispiel #22
0
 public abstract void UpdateCreatureHealth(Creature creature);
Beispiel #23
0
        /// <summary>
        /// Lets the creature know that it was damaged by another creature.
        /// Note: This method adjusts the damage as needed if hp less than 0 or
        /// greater than max.
        /// </summary>
        /// <param name="dmgAmt">Damage amt to add.</param>
        /// <param name="attacker">The name of the attacker, null if none.</param>
        /// <param name="magic">True if it was a magic attack, false otherwise.</param>
        public virtual void AddDamage(int dmgAmt, Creature attacker, bool magic)
        {
            if (CurrentHP - dmgAmt < 0) {
                dmgAmt = CurrentHP;
            } else if (CurrentHP - dmgAmt > MaxHP) {
                dmgAmt = -1 * (MaxHP - CurrentHP);
            }

            CurrentHP = (ushort)(CurrentHP - dmgAmt);
            if (dmgAmt > 0) {
                string loseString = "You lose " + dmgAmt + " hitpoint" +
                    (dmgAmt > 1 ? "s" : "") + ".";
                string leftString = " You have " + CurrentHP + " hitpoint" +
                    (CurrentHP > 1 ? "s" : "") + " left.";
                AddStatusMessage(loseString + leftString);
            }

            if (CurrentHP == 0) {
                CurrentHealthStatus = HealthStatus.DEAD;
            } else {
                //THE FORMULA! Lolz
                int divisor = MaxHP / 5;
                CurrentHealthStatus = (HealthStatus)((CurrentHP / divisor) + 1);

                if (CurrentHealthStatus >= HealthStatus.TOTAL_TYPES) {
                    throw new Exception("Invalid health status in AddDamage()");
                }
            }
        }
Beispiel #24
0
        public override void AddDamage(int dmgAmt, Creature attacker, bool magic)
        {
            base.AddDamage(dmgAmt, attacker, magic);
            totalDamageDealt += dmgAmt;
            if (attacker == null) {
                return;
            }

            foreach (AttackersInformation info in attackersInfoList) {
                if (info.Attacker == attacker) {
                    info.DamageByCreature += dmgAmt;
                    return;
                }
            }

            //Attacker not found in list... therefore add attacker
            attackersInfoList.Add(new AttackersInformation(attacker, dmgAmt));
        }
Beispiel #25
0
 public virtual void AppendNotifyOfDeath(Item corpse, Map gameMap)
 {
     if (CurrentHP == 0) {
         CreatureAttacking = null;
     }
 }
Beispiel #26
0
 public override void AddTileCreature(Creature creature, Position position, 
     byte stackpos)
 {
     if (!creature.AttackableByMonster()) {
         return;
     }
     potentialTargets.Add(creature);
 }
Beispiel #27
0
 public void SetCreatureAttacking(Creature creature)
 {
     foreach (Monster summon in summons) {
         summon.SetCreatureAttacking(creature);
     }
     CreatureAttacking = creature;
 }
Beispiel #28
0
 /// <summary>
 /// Set the master for this monster thus making it
 /// a summoned/convinced creature. To make this monster wild (again),
 /// send null as the argument.
 /// </summary>
 /// <param name="creature">Creature to set as the master.</param>
 public void SetMaster(Creature creature)
 {
     if (creature != null) {
         creature.AddSummon(this);
     }
     Master = creature;
 }
Beispiel #29
0
 public void HandlePush(Player player, Position posFrom, ushort thingID,
     byte stackpos, Position posTo, byte count, Creature creatureMoved)
 {
     HandlePush(player, posFrom, thingID, stackpos, posTo, count);
     creatureToMove = creatureMoved;
     if (!creatureMoved.IsOfType(Constants.TYPE_MOVEABLE)
         || map.GetTile(posTo) == null) {
         return;
     }
     if (map.GetTile(posTo).ContainsType(Constants.TYPE_BLOCKS_AUTO_WALK)
         || !creatureToMove.IsNextTo(posTo) || !player.IsNextTo(posFrom)) {
         return;
     }
     world.HandleMove(creatureMoved, posTo, creatureToMove.CurrentDirection);
 }
Beispiel #30
0
 private bool ExistsPath(Creature creature)
 {
     List<byte> dir = new List<byte>();
     Finder.GetPathTo(this, creature.CurrentPosition, dir, 12, false, false);
     return dir.Count > 0;
 }