Esempio n. 1
0
        /// <summary>
        ///     Adds the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="creatureSpawn">The creature spawn.</param>
        /// <param name="channelId">The channel identifier.</param>
        /// <param name="type">The type.</param>
        /// <param name="statementId">The statement identifier.</param>
        /// <param name="text">The text.</param>
        public static void Add(NetworkMessage message, ICreatureSpawn creatureSpawn, ushort channelId, SpeechType type, uint statementId, string text)
        {
            message.AddPacketType(GamePacketType.CreatureSpeech);
            message.AddUInt32(statementId);

            if (creatureSpawn == null)
            {
                message.AddUInt32(0x00);
            }
            else if (type == SpeechType.ChannelR2)
            {
                message.AddUInt32(0x00);
                type = SpeechType.Red;
            }
            else
            {
                message.AddString(creatureSpawn.Creature.Name);

                // Add level only for characters
                if (creatureSpawn is ICharacterSpawn characterSpawn)
                {
                    message.AddUInt16((ushort)characterSpawn.Level.Current);
                }
                else
                {
                    message.AddUInt16(0x00);
                }
            }

            message.AddSpeechType(type);
            message.AddUInt16(channelId);
            message.AddString(text);
        }
Esempio n. 2
0
        /// <summary>
        ///     Unregisters the creature.
        /// </summary>
        /// <param name="creatureSpawn">The creature spawn.</param>
        public void UnregisterCreature(ICreatureSpawn creatureSpawn)
        {
            _creatureSpawnsByPosition[creatureSpawn.Tile.Position].Remove(creatureSpawn);

            if (creatureSpawn is ICharacterSpawn characterSpawn)
            {
                _characterSpawnsByPosition[creatureSpawn.Tile.Position].Remove(characterSpawn);
            }
        }
        /// <summary>
        ///     Adds the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="creatureSpawn">The creature spawn.</param>
        public static void Add(NetworkMessage message, ICreatureSpawn creatureSpawn)
        {
            message.AddPacketType(GamePacketType.TileArtifactTransform);
            message.AddVector3(creatureSpawn.Tile.Position);
            message.AddByte(creatureSpawn.StackPosition);

            // TODO: Find out what this value means
            message.AddUInt16(0x63);
            message.AddUInt32(creatureSpawn.Id);
            message.AddDirection(creatureSpawn.Direction);

            // TODO: characterSpawn.CanWalkThrough(creatureSpawn)
            message.AddBoolean(false);
        }
        /// <summary>
        ///     Determines whether this instance can see the specified creature spawn.
        /// </summary>
        /// <param name="self">The self.</param>
        /// <param name="creatureSpawn">The creature spawn.</param>
        /// <returns>
        ///     <c>true</c> if this instance can see the specified creature spawn; otherwise, <c>false</c>.
        /// </returns>
        public static bool CanSee(this ICharacterSpawn self, ICreatureSpawn creatureSpawn)
        {
            if (self == creatureSpawn)
            {
                return(true);
            }

            // TODO: Ghost Mode
            //if (creature.isInGhostMode() && !Group.UnrestrictedAccess)
            //    return false;

            // TODO: Implement invisibility immunity
            return(!creatureSpawn.IsInvisible && ((ICreatureSpawn)self).CanSee(creatureSpawn));
        }
Esempio n. 5
0
        /// <summary>
        ///     Registers the creature.
        /// </summary>
        /// <param name="creatureSpawn">The creature spawn.</param>
        public void RegisterCreature(ICreatureSpawn creatureSpawn)
        {
            if (!_creatureSpawnsByPosition.ContainsKey(creatureSpawn.Tile.Position))
            {
                _creatureSpawnsByPosition.Add(creatureSpawn.Tile.Position, new HashSet <ICreatureSpawn>());
            }
            _creatureSpawnsByPosition[creatureSpawn.Tile.Position].Add(creatureSpawn);

            if (creatureSpawn is ICharacterSpawn characterSpawn)
            {
                if (!_characterSpawnsByPosition.ContainsKey(creatureSpawn.Tile.Position))
                {
                    _characterSpawnsByPosition.Add(creatureSpawn.Tile.Position, new HashSet <ICharacterSpawn>());
                }
                _characterSpawnsByPosition[creatureSpawn.Tile.Position].Add(characterSpawn);
            }
        }
Esempio n. 6
0
        /// <summary>
        ///     Registers the creature.
        /// </summary>
        /// <param name="creatureSpawn">The creature spawn.</param>
        public void RegisterCreature(ICreatureSpawn creatureSpawn)
        {
            _creatureSpawns.Add(creatureSpawn);

            if (!_creatureSpawnById.ContainsKey(creatureSpawn.Id))
            {
                _creatureSpawnById.Add(creatureSpawn.Id, null);
            }

            _creatureSpawnById[creatureSpawn.Id] = creatureSpawn;

            string lowerCaseName = creatureSpawn.Creature.Name.Trim().ToLower();

            if (!_creatureSpawnsByName.ContainsKey(lowerCaseName))
            {
                _creatureSpawnsByName.Add(lowerCaseName, new HashSet <ICreatureSpawn>());
            }

            _creatureSpawnsByName[lowerCaseName].Add(creatureSpawn);
        }
Esempio n. 7
0
        /// <summary>
        ///     Adds the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="creatureSpawn">The creature spawn.</param>
        /// <param name="type">The type.</param>
        /// <param name="statementId">The statement identifier.</param>
        /// <param name="text">The text.</param>
        /// <param name="position">The position.</param>
        public static void Add(NetworkMessage message, ICreatureSpawn creatureSpawn, SpeechType type, uint statementId, string text, IVector3 position)
        {
            message.AddPacketType(GamePacketType.CreatureSpeech);
            message.AddUInt32(statementId);
            message.AddString(creatureSpawn.Creature.Name);

            // Add level only for characters
            if (creatureSpawn is ICharacterSpawn characterSpawn)
            {
                message.AddUInt16((ushort)characterSpawn.Level.Current);
            }
            else
            {
                message.AddUInt16(0x00);
            }

            message.AddSpeechType(type);
            message.AddVector3(position ?? creatureSpawn.Tile.Position);
            message.AddString(text);
        }
        /// <summary>
        ///     Gets the step duration.
        /// </summary>
        /// <param name="self">The self.</param>
        /// <returns>The step duration.</returns>
        public static TimeSpan StepDuration(this ICreatureSpawn self)
        {
            ITile tile = self.Tile;

            int    calculatedStepSpeed;
            ushort stepSpeed = self.Speed.WalkSpeed;

            // TODO: This value was originally hard-cored (SpeedB)
            if (stepSpeed <= -261.29)
            {
                calculatedStepSpeed = 1;
            }
            else
            {
                // TODO: These values were originally hard-coded (SpeedA, SpeedB, SpeedC)
                calculatedStepSpeed = (int)Math.Floor(857.36 * Math.Log((double)stepSpeed / 2 + 261.29) + -4795.01 + 0.5);
                if (calculatedStepSpeed <= 0)
                {
                    calculatedStepSpeed = 1;
                }
            }

            // TODO: groundSpeed should not be hard-coded
            ushort groundSpeed = 150;

            if (tile.Ground?.Item?.Speed != null)
            {
                groundSpeed = tile.Ground.Item.Speed.Value;
            }

            // TODO: 1000 should not be hard-coded
            int duration = (int)Math.Floor(1000 * groundSpeed / (double)calculatedStepSpeed);

            // TODO: 50 should not be hard-coded
            int stepDuration = (int)Math.Ceiling(duration / (double)50) * 50;

            return(TimeSpan.FromMilliseconds(stepDuration));
        }
 /// <inheritdoc />
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:Tibia.Network.Game.UnregisteredTileCreatureEventArgs" />
 ///     class.
 /// </summary>
 /// <param name="creatureSpawn">The creature spawn.</param>
 public UnregisteredTileCreatureEventArgs(ICreatureSpawn creatureSpawn)
 {
     CreatureSpawn = creatureSpawn;
 }
Esempio n. 10
0
 /// <inheritdoc />
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:Tibia.Network.Game.RegisteringTileCreatureEventArgs" />
 ///     class.
 /// </summary>
 /// <param name="creatureSpawn">The creature spawn.</param>
 public RegisteringTileCreatureEventArgs(ICreatureSpawn creatureSpawn)
 {
     CreatureSpawn = creatureSpawn;
 }
Esempio n. 11
0
 /// <summary>
 ///     Determines whether this instance can see the specified creature spawn.
 /// </summary>
 /// <param name="self">The self.</param>
 /// <param name="creatureSpawn">The creature spawn.</param>
 /// <returns>
 ///     <c>true</c> if this instance can see the specified creature spawn; otherwise, <c>false</c>.
 /// </returns>
 public static bool CanSee(this ICreatureSpawn self, ICreatureSpawn creatureSpawn)
 {
     return(!creatureSpawn.IsInvisible);
 }
Esempio n. 12
0
        /// <summary>
        ///     Adds the creature.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="characterSpawn">The character spawn.</param>
        /// <param name="creatureSpawn">The creature spawn.</param>
        /// <param name="known">if set to <c>true</c> [known].</param>
        /// <param name="removeKnown">The remove known.</param>
        public static void AddCreature(NetworkMessage message, ICharacterSpawn characterSpawn, ICreatureSpawn creatureSpawn, bool known, uint removeKnown)
        {
            // TODO: This method MUST be called "Add" for consistency
            if (known)
            {
                // TODO: MAGIC NUMBER DETECTED!
                message.AddUInt16(0x62); // known
                message.AddUInt32(creatureSpawn.Id);
            }
            else
            {
                // TODO: MAGIC NUMBER DETECTED!
                message.AddUInt16(0x61); // unknown
                message.AddUInt32(removeKnown);
                message.AddUInt32(creatureSpawn.Id);
                message.AddCreatureType(creatureSpawn.Creature.CreatureType);
                message.AddString(creatureSpawn.Creature.Name);
            }

            message.AddPercent(creatureSpawn.Health.ToPercent());
            message.AddDirection(creatureSpawn.Direction);
            message.AddAppearance(creatureSpawn.Outfit, creatureSpawn.Mount);
            message.AddByte(creatureSpawn.LightInfo.Level);
            message.AddByte(creatureSpawn.LightInfo.Color);
            message.AddUInt16(creatureSpawn.Speed.WalkSpeed);
            message.AddSkullType(creatureSpawn.Skull.Type);
            message.AddPartyShield(characterSpawn.GetPartyShield(creatureSpawn as CharacterSpawn));

            if (!known)
            {
                message.AddWarIcon(creatureSpawn.WarIcon);
            }

            CreatureType creatureType = creatureSpawn.Creature.CreatureType;

            if (creatureType == CreatureType.Monster && creatureSpawn is ISummon summon)
            {
                creatureType = summon.Master == characterSpawn ? CreatureType.SummonOwn : CreatureType.SummonOthers;
            }

            message.AddCreatureType(creatureType);
            message.AddSpeechBubble(creatureSpawn.Creature.SpeechBubble);

            // TODO: Implement marked/unmarked??
            message.AddByte(0xFF);

            // TODO: Implement helpers
            //if (otherPlayer)
            //{
            //    msg.add<uint16_t>(otherPlayer->getHelpers());
            //}
            //else
            //{
            // TODO: MAGIC NUMBER DETECTED!
            message.AddUInt16(0x00);
            //}
            message.AddBoolean(creatureSpawn is ISolidBlock);
        }
Esempio n. 13
0
 /// <summary>
 ///     Adds the specified message.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="character">The character.</param>
 /// <param name="position">The position.</param>
 /// <param name="stackPosition">The stack position.</param>
 /// <param name="creature">The creature.</param>
 /// <param name="known">if set to <c>true</c> [known].</param>
 /// <param name="removeKnown">The remove known.</param>
 public static void Add(NetworkMessage message, ICharacterSpawn character, IVector3 position, byte stackPosition, ICreatureSpawn creature, bool known, uint removeKnown)
 {
     message.AddPacketType(GamePacketType.TileAddArtifact);
     message.AddVector3(position);
     message.AddByte(stackPosition);
     AddCreature(message, character, creature, known, removeKnown);
 }
Esempio n. 14
0
        /// <inheritdoc />
        /// <summary>
        ///     Executes the command.
        /// </summary>
        /// <param name="caster">The caster.</param>
        /// <param name="args">The arguments.</param>
        protected override void ExecuteCommand(ICharacterSpawn caster, string[] args)
        {
            if (args.Length == 0)
            {
                return;
            }

            string target = args.FirstOrDefault();

            if (string.IsNullOrWhiteSpace(target))
            {
                return;
            }

            target = target.Trim().ToLower();
            IVector3 targetPosition;

            switch (target)
            {
            case "xyz":
            {
                string position = args.Skip(1).FirstOrDefault();
                if (string.IsNullOrWhiteSpace(position))
                {
                    return;
                }

                string[] xyz = position.Split(',');
                targetPosition = new Vector3(int.Parse(xyz[0].Trim()), int.Parse(xyz[1].Trim()), int.Parse(xyz[2].Trim()));
                break;
            }

            case "temple":
            {
                targetPosition = caster.Town.TemplePosition;
                break;
            }

            case "town":
            {
                string townName = args.Skip(1).FirstOrDefault();
                if (string.IsNullOrWhiteSpace(townName))
                {
                    return;
                }

                ITown town = _townService.GetTownByName(townName.Trim().ToLower());
                targetPosition = town.TemplePosition;
                break;
            }

            case "creature":
            {
                string creatureName = args.Skip(1).FirstOrDefault();
                if (string.IsNullOrWhiteSpace(creatureName))
                {
                    return;
                }

                IEnumerable <ICreatureSpawn> creatureSpawns = _creatureSpawnService.GetCreatureSpawnsByName(creatureName.Trim().ToLower());
                ICreatureSpawn firstMatch = creatureSpawns.FirstOrDefault();
                if (firstMatch == null)
                {
                    caster.Connection.SendTextMessage(TextMessageType.StatusSmall, "A creature with this name does not exist.");
                    return;
                }

                targetPosition = firstMatch.Tile.Position;
                break;
            }

            case "up":
            {
                IVector3 currentPosition = caster.Tile.Position;
                targetPosition = new Vector3(currentPosition.X, currentPosition.Y, currentPosition.Z - 1);
                break;
            }

            case "down":
            {
                IVector3 currentPosition = caster.Tile.Position;
                targetPosition = new Vector3(currentPosition.X, currentPosition.Y, currentPosition.Z + 1);
                break;
            }

            case "north":
            {
                IVector3 currentPosition = caster.Tile.Position;
                targetPosition = new Vector3(currentPosition.X, currentPosition.Y - 1, currentPosition.Z);
                break;
            }

            case "south":
            {
                IVector3 currentPosition = caster.Tile.Position;
                targetPosition = new Vector3(currentPosition.X, currentPosition.Y + 1, currentPosition.Z);
                break;
            }

            case "east":
            {
                IVector3 currentPosition = caster.Tile.Position;
                targetPosition = new Vector3(currentPosition.X + 1, currentPosition.Y, currentPosition.Z);
                break;
            }

            case "west":
            {
                IVector3 currentPosition = caster.Tile.Position;
                targetPosition = new Vector3(currentPosition.X - 1, currentPosition.Y, currentPosition.Z);
                break;
            }

            default: { throw new ArgumentOutOfRangeException(nameof(target), target, null); }
            }

            caster.Connection.MoveCreature(caster, targetPosition);
            caster.Connection.SendEffect(targetPosition, Effect.Teleport);
        }