public void Kill(Session session) { IsAlive = false; // Create and send the death notice string killMessage = $"{session.Player.Name} has killed {Name}."; var creatureDeathEvent = new GameEventDeathNotice(session, killMessage); session.Network.EnqueueSend(creatureDeathEvent); // MovementEvent: (Hand-)Combat or in the case of smite: from Standing to Death // TODO: Check if the duration of the motion can somehow be computed GeneralMotion motionDeath = new GeneralMotion(MotionStance.Standing, new MotionItem(MotionCommand.Dead)); QueuedGameAction actionDeath = new QueuedGameAction(this.Guid.Full, motionDeath, 2.0f, true, GameActionType.MovementEvent); session.Player.AddToActionQueue(actionDeath); // Create Corspe and set a location on the ground // TODO: set text of killer in description and find a better computation for the location, some corpse could end up in the ground var corpse = CorpseObjectFactory.CreateCorpse(this, this.Location); corpse.Location.PositionY -= corpse.PhysicsData.ObjScale; corpse.Location.PositionZ -= corpse.PhysicsData.ObjScale / 2; // Remove Creature from Landblock and add Corpse in that location via the ActionQueue to honor the motion delays QueuedGameAction removeCreature = new QueuedGameAction(this.Guid.Full, this, true, true, GameActionType.ObjectDelete); QueuedGameAction addCorpse = new QueuedGameAction(this.Guid.Full, corpse, true, GameActionType.ObjectCreate); session.Player.AddToActionQueue(removeCreature); session.Player.AddToActionQueue(addCorpse); }
public static void Handle(ClientMessage message, Session session) { if (session.Player.Positions.ContainsKey(PositionType.Sanctuary)) { // session.Player.Teleport(session.Player.Positions[PositionType.Sanctuary]); string msg = $"{session.Player.Name} is recalling to the lifestone."; var sysChatMessage = new GameMessageSystemChat(msg, ChatMessageType.Recall); session.Player.Mana.Current = session.Player.Mana.Current / 2; var updatePlayersMana = new GameMessagePrivateUpdateAttribute2ndLevel(session, Vital.Mana, session.Player.Mana.Current); var updateCombatMode = new GameMessagePrivateUpdatePropertyInt(session, PropertyInt.CombatMode, 1); var motionLifestoneRecall = new GeneralMotion(MotionStance.Standing, new MotionItem(MotionCommand.LifestoneRecall)); var animationEvent = new GameMessageUpdateMotion(session.Player, session, motionLifestoneRecall); // TODO: This needs to be changed to broadcast sysChatMessage to only those in local chat hearing range // FIX: Recall text isn't being broadcast yet, need to address session.Network.EnqueueSend(updatePlayersMana, updateCombatMode, sysChatMessage); session.Player.EnqueueMovementEvent(motionLifestoneRecall, session.Player.Guid); session.Player.SetDelayedTeleport(TimeSpan.FromSeconds(14), session.Player.Positions[PositionType.Sanctuary]); } else { ChatPacket.SendServerMessage(session, "Your spirit has not been attuned to a sanctuary location.", ChatMessageType.Broadcast); } }
public QueuedGameAction(uint objectId, GeneralMotion motion, GameActionType actionType) { this.ObjectId = objectId; this.Motion = motion; this.ActionType = actionType; this.StartTime = WorldManager.PortalYearTicks; this.EndTime = this.StartTime; }
public QueuedGameAction(uint objectId, GeneralMotion motion, double duration, bool respectDelay, GameActionType actionType) { this.ObjectId = objectId; this.Motion = motion; this.RespectDelay = respectDelay; this.ActionType = actionType; this.StartTime = WorldManager.PortalYearTicks; this.EndTime = this.StartTime + duration; }
public static BroadcastEventArgs CreateMovementEvent(WorldObject sender, GeneralMotion motion) { return(new BroadcastEventArgs() { ActionType = BroadcastAction.MovementEvent, Sender = sender, Motion = motion }); }
public static void Movement(Session session, params string[] parameters) { ushort forwardCommand = 24; if ((parameters?.Length > 0)) { forwardCommand = (ushort)Convert.ToInt16(parameters[0]); } var movement = new GeneralMotion(MotionStance.Standing); movement.MovementData.ForwardCommand = forwardCommand; session.Network.EnqueueSend(new GameMessageUpdateMotion(session.Player, session, movement)); movement = new GeneralMotion(MotionStance.Standing); session.Network.EnqueueSend(new GameMessageUpdateMotion(session.Player, session, movement)); }
public virtual void OnKill(Session session) { IsAlive = false; // This will determine if the derived type is a player var isDerivedPlayer = Guid.IsPlayer(); // TODO: Implement some proper respawn timers, check the generators for that RespawnTime = WorldManager.PortalYearTicks + 10; if (!isDerivedPlayer) { // Create and send the death notice string killMessage = $"{session.Player.Name} has killed {Name}."; var creatureDeathEvent = new GameEventDeathNotice(session, killMessage); session.Network.EnqueueSend(creatureDeathEvent); } // MovementEvent: (Hand-)Combat or in the case of smite: from Standing to Death // TODO: Check if the duration of the motion can somehow be computed GeneralMotion motionDeath = new GeneralMotion(MotionStance.Standing, new MotionItem(MotionCommand.Dead)); QueuedGameAction actionDeath = new QueuedGameAction(this.Guid.Full, motionDeath, 2.0f, true, GameActionType.MovementEvent); session.Player.AddToActionQueue(actionDeath); // Create Corspe and set a location on the ground // TODO: set text of killer in description and find a better computation for the location, some corpse could end up in the ground var corpse = CorpseObjectFactory.CreateCorpse(this, this.Location); corpse.Location.PositionY -= corpse.PhysicsData.ObjScale; corpse.Location.PositionZ -= corpse.PhysicsData.ObjScale / 2; // Corpses stay on the ground for 5 * player level but minimum 1 hour // corpse.DespawnTime = Math.Max((int)session.Player.PropertiesInt[Enum.Properties.PropertyInt.Level] * 5, 360) + WorldManager.PortalYearTicks; // as in live corpse.DespawnTime = 20 + WorldManager.PortalYearTicks; // only for testing // If the object is a creature, Remove it from from Landblock if (!isDerivedPlayer) { QueuedGameAction removeCreature = new QueuedGameAction(this.Guid.Full, this, true, true, GameActionType.ObjectDelete); session.Player.AddToActionQueue(removeCreature); } // Add Corpse in that location via the ActionQueue to honor the motion delays QueuedGameAction addCorpse = new QueuedGameAction(this.Guid.Full, corpse, true, GameActionType.ObjectCreate); session.Player.AddToActionQueue(addCorpse); }
public static void Animation(Session session, params string[] parameters) { uint animationId; try { animationId = Convert.ToUInt32(parameters[0]); } catch (Exception) { ChatPacket.SendServerMessage(session, $"Invalid Animation value", ChatMessageType.Broadcast); return; } GeneralMotion motion = new GeneralMotion(MotionStance.Standing, new MotionItem((MotionCommand)animationId)); session.Player.EnqueueMovementEvent(motion, session.Player.Guid); }
public void SetCombatMode(CombatMode newCombatMode) { log.InfoFormat("Changing combat mode for {0} to {1}", this.Guid, newCombatMode); // TODO: any sort of validation CombatMode = newCombatMode; switch (CombatMode) { case CombatMode.Peace: SetMotionState(new GeneralMotion(MotionStance.Standing)); break; case CombatMode.Melee: var gm = new GeneralMotion(MotionStance.UANoShieldAttack); gm.MovementData.CurrentStyle = (ushort)MotionStance.UANoShieldAttack; SetMotionState(gm); break; } }
public static void Handle(ClientMessage clientMessage, Session session) { string message = $"{session.Player.Name} is recalling to the marketplace."; var sysChatMessage = new GameMessageSystemChat(message, ChatMessageType.Recall); var updateCombatMode = new GameMessagePrivateUpdatePropertyInt(session, PropertyInt.CombatMode, 1); var motionMarketplaceRecall = new GeneralMotion(MotionStance.Standing, new MotionItem(MotionCommand.MarketplaceRecall)); var animationEvent = new GameMessageUpdateMotion(session.Player, session, motionMarketplaceRecall); // TODO: This needs to be changed to broadcast sysChatMessage to only those in local chat hearing range // FIX: Recall text isn't being broadcast yet, need to address session.Network.EnqueueSend(updateCombatMode, sysChatMessage); session.Player.EnqueueMovementEvent(motionMarketplaceRecall, session.Player.Guid); session.Player.SetDelayedTeleport(TimeSpan.FromSeconds(14), marketplaceDrop); }
private void HandleGameAction(QueuedGameAction action, Player player) { switch (action.ActionType) { case GameActionType.TalkDirect: { // TODO: remove this hack (using TalkDirect) ASAP var g = new ObjectGuid(action.ObjectId); WorldObject obj = (WorldObject)player; if (worldObjects.ContainsKey(g)) { obj = worldObjects[g]; } DeathMessageArgs d = new DeathMessageArgs(action.ActionBroadcastMessage, new ObjectGuid(action.ObjectId), new ObjectGuid(action.SecondaryObjectId)); HandleDeathMessage(obj, d); break; } case GameActionType.TeleToHouse: case GameActionType.TeleToLifestone: case GameActionType.TeleToMansion: case GameActionType.TeleToMarketPlace: case GameActionType.TeleToPkArena: case GameActionType.TeleToPklArena: { player.Teleport(action.ActionLocation); break; } case GameActionType.ApplyVisualEffect: { var g = new ObjectGuid(action.ObjectId); WorldObject obj = (WorldObject)player; if (worldObjects.ContainsKey(g)) { obj = worldObjects[g]; } var particleEffect = (PlayScript)action.SecondaryObjectId; HandleParticleEffectEvent(obj, particleEffect); break; } case GameActionType.ApplySoundEffect: { var g = new ObjectGuid(action.ObjectId); WorldObject obj = (WorldObject)player; if (worldObjects.ContainsKey(g)) { obj = worldObjects[g]; } var soundEffect = (Sound)action.SecondaryObjectId; HandleSoundEvent(obj, soundEffect); break; } case GameActionType.PutItemInContainer: { var playerId = new ObjectGuid(action.ObjectId); var inventoryId = new ObjectGuid(action.SecondaryObjectId); if (playerId.IsPlayer()) { Player aPlayer = null; WorldObject inventoryItem = null; if (worldObjects.ContainsKey(playerId) && worldObjects.ContainsKey(inventoryId)) { aPlayer = (Player)worldObjects[playerId]; inventoryItem = worldObjects[inventoryId]; } if ((aPlayer != null) && (inventoryItem != null)) { var motion = new GeneralMotion(MotionStance.Standing); motion.MovementData.ForwardCommand = (ushort)MotionCommand.Pickup; aPlayer.Session.Network.EnqueueSend(new GameMessageUpdatePosition(aPlayer), new GameMessageUpdateMotion(aPlayer, aPlayer.Session, motion), new GameMessageSound(aPlayer.Guid, Sound.PickUpItem, (float)1.0)); // Add to the inventory list. aPlayer.AddToInventory(inventoryItem); LandblockManager.RemoveObject(inventoryItem); motion = new GeneralMotion(MotionStance.Standing); aPlayer.Session.Network.EnqueueSend(new GameMessagePrivateUpdatePropertyInt(aPlayer.Session, PropertyInt.EncumbVal, aPlayer.GameData.Burden), new GameMessagePutObjectInContainer(aPlayer.Session, aPlayer, inventoryId), new GameMessageUpdateMotion(aPlayer, aPlayer.Session, motion), new GameMessageUpdateInstanceId(inventoryId, playerId), new GameMessagePickupEvent(aPlayer.Session, inventoryItem)); aPlayer.TrackObject(inventoryItem); } } break; } case GameActionType.DropItem: { var g = new ObjectGuid(action.ObjectId); // ReSharper disable once InconsistentlySynchronizedField if (worldObjects.ContainsKey(g)) { var playerId = new ObjectGuid(action.ObjectId); var inventoryId = new ObjectGuid(action.SecondaryObjectId); if (playerId.IsPlayer()) { Player aPlayer = null; WorldObject inventoryItem = null; if (worldObjects.ContainsKey(playerId)) { aPlayer = (Player)worldObjects[playerId]; inventoryItem = aPlayer.GetInventoryItem(inventoryId); aPlayer.RemoveFromInventory(inventoryId); } if ((aPlayer != null) && (inventoryItem != null)) { var targetContainer = new ObjectGuid(0); aPlayer.Session.Network.EnqueueSend( new GameMessagePrivateUpdatePropertyInt( aPlayer.Session, PropertyInt.EncumbVal, (uint)aPlayer.Session.Player.GameData.Burden)); var motion = new GeneralMotion(MotionStance.Standing); motion.MovementData.ForwardCommand = (ushort)MotionCommand.Pickup; aPlayer.Session.Network.EnqueueSend( new GameMessageUpdateMotion(aPlayer, aPlayer.Session, motion), new GameMessageUpdateInstanceId(inventoryId, targetContainer)); motion = new GeneralMotion(MotionStance.Standing); aPlayer.Session.Network.EnqueueSend( new GameMessageUpdateMotion(aPlayer, aPlayer.Session, motion), new GameMessagePutObjectIn3d(aPlayer.Session, aPlayer, inventoryId), new GameMessageSound(aPlayer.Guid, Sound.DropItem, (float)1.0), new GameMessageUpdateInstanceId(inventoryId, targetContainer)); // This is the sequence magic - adds back into 3d space seem to be treated like teleport. inventoryItem.Sequences.GetNextSequence(SequenceType.ObjectTeleport); inventoryItem.Sequences.GetNextSequence(SequenceType.ObjectVector); LandblockManager.AddObject(inventoryItem); aPlayer.Session.Network.EnqueueSend(new GameMessageUpdatePosition(inventoryItem)); } } } break; } case GameActionType.MovementEvent: { var g = new ObjectGuid(action.ObjectId); WorldObject obj = (WorldObject)player; if (worldObjects.ContainsKey(g)) { obj = worldObjects[g]; } var motion = action.Motion; HandleMovementEvent(obj, motion); break; } case GameActionType.ObjectCreate: { this.AddWorldObject(action.WorldObject); break; } case GameActionType.ObjectDelete: { this.RemoveWorldObject(action.WorldObject.Guid, false); break; } case GameActionType.QueryHealth: { if (action.ObjectId == 0) { // Deselect the formerly selected Target player.SelectedTarget = 0; break; } object target = null; var targetId = new ObjectGuid(action.ObjectId); // Remember the selected Target player.SelectedTarget = action.ObjectId; // TODO: once items are implemented check if there are items that can trigger // the QueryHealth event. So far I believe it only gets triggered for players and creatures if (targetId.IsPlayer() || targetId.IsCreature()) { if (this.worldObjects.ContainsKey(targetId)) { target = this.worldObjects[targetId]; } if (target == null) { // check adjacent landblocks for the targetId foreach (var block in adjacencies) { if (block.Value != null) { if (block.Value.worldObjects.ContainsKey(targetId)) { target = block.Value.worldObjects[targetId]; } } } } if (target != null) { float healthPercentage = 0; if (targetId.IsPlayer()) { Player tmpTarget = (Player)target; healthPercentage = (float)tmpTarget.Health.Current / (float)tmpTarget.Health.MaxValue; } if (targetId.IsCreature()) { Creature tmpTarget = (Creature)target; healthPercentage = (float)tmpTarget.Health.Current / (float)tmpTarget.Health.MaxValue; } var updateHealth = new GameEventUpdateHealth(player.Session, targetId.Full, healthPercentage); player.Session.Network.EnqueueSend(updateHealth); } } break; } case GameActionType.Use: { var g = new ObjectGuid(action.ObjectId); if (worldObjects.ContainsKey(g)) { WorldObject obj = worldObjects[g]; switch (obj.Type) { case Enum.ObjectType.Portal: { // validate within use range :: set to a fixed value as static Portals are normally OnCollide usage float rangeCheck = 5.0f; if (player.Location.SquaredDistanceTo(obj.Location) < rangeCheck) { PortalDestination portalDestination = DatabaseManager.World.GetPortalDestination(obj.WeenieClassid); if (portalDestination != null) { player.Session.Player.Teleport(portalDestination.Position); // always send useDone event var sendUseDoneEvent = new GameEventUseDone(player.Session); player.Session.Network.EnqueueSend(sendUseDoneEvent); } else { string serverMessage = "Portal destination for portal ID " + obj.WeenieClassid + " not yet implemented!"; var usePortalMessage = new GameMessageSystemChat(serverMessage, ChatMessageType.System); // always send useDone event var sendUseDoneEvent = new GameEventUseDone(player.Session); player.Session.Network.EnqueueSend(usePortalMessage, sendUseDoneEvent); } } else { // always send useDone event var sendUseDoneEvent = new GameEventUseDone(player.Session); player.Session.Network.EnqueueSend(sendUseDoneEvent); } break; } case Enum.ObjectType.LifeStone: { string serverMessage = null; // validate within use range float radiusSquared = obj.GameData.UseRadius * obj.GameData.UseRadius; var motionSanctuary = new GeneralMotion(MotionStance.Standing, new MotionItem(MotionCommand.Sanctuary)); var animationEvent = new GameMessageUpdateMotion(player, player.Session, motionSanctuary); // This event was present for a pcap in the training dungeon.. Why? The sound comes with animationEvent... var soundEvent = new GameMessageSound(obj.Guid, Sound.LifestoneOn, 1); if (player.Location.SquaredDistanceTo(obj.Location) >= radiusSquared) { serverMessage = "You wandered too far to attune with the Lifestone!"; } else { player.SetCharacterPosition(PositionType.Sanctuary, player.Location); // create the outbound server message serverMessage = "You have attuned your spirit to this Lifestone. You will resurrect here after you die."; player.EnqueueMovementEvent(motionSanctuary, player.Guid); player.Session.Network.EnqueueSend(soundEvent); } var lifestoneBindMessage = new GameMessageSystemChat(serverMessage, ChatMessageType.Magic); // always send useDone event var sendUseDoneEvent = new GameEventUseDone(player.Session); player.Session.Network.EnqueueSend(lifestoneBindMessage, sendUseDoneEvent); break; } } } break; } } }
public void HandleMovementEvent(WorldObject sender, GeneralMotion motion) { BroadcastEventArgs args = BroadcastEventArgs.CreateMovementEvent(sender, motion); Broadcast(args, true, Quadrant.All); }