public void Execute(Character.NPC actor, ITrigger trigger = null) { //first let's check to see if we got any messages telling us we are being attacked and use that //person attacking us as the target //if that gets us nowhere, we need to then just kill the first non npc we find in our same location Rooms.Room room = Rooms.Room.GetRoom(actor.Location); List <string> playersAtThisLocation = room.GetObjectsInRoom(Rooms.Room.RoomObjects.Players); double minutesSinceLastCombat = (DateTime.Now.ToUniversalTime() - actor.LastCombatTime).TotalMinutes; //let's start by seeing if we had a last target and the last combat time has been less than 5 minutes ago, if so and he's here, it's payback time if (actor.LastTarget != null && minutesSinceLastCombat < 5) { playersAtThisLocation.AddRange(room.GetObjectsInRoom(Rooms.Room.RoomObjects.Npcs)); //we may have been attacking an npc so let's add them in if (playersAtThisLocation.Contains(actor.LastTarget)) //yeah our previous target is here { actor.CurrentTarget = actor.LastTarget; } } //if we don't have a target and we have never been in combat yet, then we are going to find a target OR //we've lost interest in our previous target but still have a blooddlust for another 10 minutes //so a random person is going to get attacked unless it's been too long since we last attacked someone //at this point we should only have actual players in the list to attack (maybe add something so some NPCs can attack other NPCs) if ((actor.LastCombatTime == DateTime.MinValue.ToUniversalTime() && actor.CurrentTarget == null) || (actor.CurrentTarget == null && minutesSinceLastCombat >= 5 && minutesSinceLastCombat < 15)) { if (playersAtThisLocation.Count > 0) { actor.CurrentTarget = playersAtThisLocation[Extensions.RandomNumber.GetRandomNumber().NextNumber(0, playersAtThisLocation.Count)]; } } //we have a target let's attack if (actor.CurrentTarget != null) { if (playersAtThisLocation.Contains(actor.CurrentTarget)) { Commands.CommandParser.ExecuteCommand(actor, "EMOTE", "growls menancingly at " + MySockets.Server.GetAUser(actor.CurrentTarget).Player.FirstName.CamelCaseWord() + "!"); actor.NextAiAction = DateTime.Now.AddSeconds(10).ToUniversalTime(); //give player time to react, maybe even get the first hit actor.Fsm.ChangeState(Combat.GetState(), actor); } } else { //no targets in sight let's enter hunt mode until things cool down actor.Fsm.ChangeState(Hunt.GetState(), actor); } }
public void Execute(Character.NPC actor, ITrigger trigger = null) { if (!actor.IsDead() && !actor.InCombat) { Rooms.Room room = Rooms.Room.GetRoom(actor.Location); room.GetRoomExits(); List <Rooms.Exits> availableExits = room.RoomExits; if (DateTime.Now.ToUniversalTime() > actor.NextAiAction) //so it's time for this AI state to execute { Commands.CommandParser.ExecuteCommand(actor, availableExits[Extensions.RandomNumber.GetRandomNumber().NextNumber(0, availableExits.Count)].Direction); actor.NextAiAction = DateTime.Now.AddSeconds(Extensions.RandomNumber.GetRandomNumber().NextNumber(60, 121)).ToUniversalTime(); //set when we want this action to execute next if (!FSM.ContinueWithThisState()) { actor.Fsm.ChangeState(Speak.GetState(), actor); } } } if (actor.InCombat) { actor.Fsm.ChangeState(Combat.GetState(), actor); } }