public void UseMoveOnAllies(BattleSetup setup, TargetCollection targets) { Parties.Party party = null; if (owner.Player.IsInParty()) { party = Parties.PartyManager.FindPlayerParty(owner); } //List<ICharacter> targets = MoveProcessor.GetTargetsInRange(setup.Move.RangeType, setup.Move.Range, setup.AttackerMap, this, owner.Player.X, owner.Player.Y, owner.Player.Direction); Move move = setup.SetdownMove(); // Attack any players that are on the map foreach (ICharacter i in targets.Friends) { if (i.CharacterType == Enums.CharacterType.Recruit && Ranks.IsAllowed(((Recruit)i).Owner, Enums.Rank.Moniter) && !((Recruit)i).Owner.Player.Hunted && !((Recruit)i).Owner.Player.Dead) { } else { setup.Defender = i; BattleProcessor.MoveHitCharacter(setup); setup.SetupMove(move); if (setup.Cancel) { return; } } } }
public void ThrowHeldItem() { BattleSetup setup = new BattleSetup(); setup.Attacker = this; Scripting.ScriptManager.InvokeSub("ThrewItem", setup, HeldItem, 0); BattleProcessor.FinalizeAction(setup); }
//public void UseMoveOnSelf(int moveNum) { // BattleProcessor.MoveHitCharacter(this, this, moveNum); // Messenger.SpellAnim(moveNum, this.MapID, this.X, this.Y); //} public void UseMove(int moveSlot) { BattleSetup setup = new BattleSetup(); setup.Attacker = this; setup.moveSlot = moveSlot; BattleProcessor.HandleAttack(setup); BattleProcessor.FinalizeAction(setup); }
public void AttackMonsterTest() { RollingDice rollingDice = new RollingDice(); Player player = new Player(2); BattleProcessor battleProcessor = new BattleProcessor(); Monster monster = new Yeti(1); monster.Attack = 100; battleProcessor.MonsterAttack(player, monster); Assert.False(battleProcessor.CheckPlayerAlive(player)); }
public void UseHeldItem() { if (HeldItem == null) { return; } BattleSetup setup = new BattleSetup(); setup.Attacker = this; BattleProcessor.HandleItemUse(HeldItem, 0, setup); BattleProcessor.FinalizeAction(setup); }
public void UseMoveOnFoes(BattleSetup setup, TargetCollection targets) { // Attack any players that are on the map //List<ICharacter> targets = MoveProcessor.GetTargetsInRange(setup.Move.RangeType, setup.Move.Range, setup.AttackerMap, this, X, Y, Direction); Move move = setup.SetdownMove(); foreach (ICharacter i in targets.Foes) { setup.Defender = i; BattleProcessor.MoveHitCharacter(setup); setup.SetupMove(move); if (setup.Cancel) { return; } } }
public void UseMove(int moveSlot) { if (owner.Player.Dead) { return; } owner.Player.Map.ProcessingPaused = false; if (owner.Player.ProtectionOff) { owner.Player.Hunted = true; Messenger.SendHunted(owner); } if (!Core.GetTickCount().Elapsed(owner.Player.PauseTimer, 0)) { return; } if (moveSlot > -1 && moveSlot < 4) { Move move = MoveManager.Moves[Moves[moveSlot].MoveNum]; IMap currentMap = owner.Player.GetCurrentMap(); if (move.KeyItem > 0) { bool doorOpened = UseMoveKey(currentMap, move, moveSlot); if (doorOpened) { return; } } } BattleSetup setup = new BattleSetup(); setup.Attacker = this; setup.moveSlot = moveSlot; BattleProcessor.HandleAttack(setup); BattleProcessor.FinalizeAction(setup); }
public World() { Rnd = new Random(Constants.WORLD_SEED); BattleProcessor = new BattleProcessor(); CreatureManager = new CreatureManager(); LiveMap = new LiveMap(); if (Constants.GAME_MODE) { if (m_startingLayerType == null) { throw new ApplicationException("Нужно задать тип стартового уровня"); } m_layers.Add(CurrentLayer = (WorldLayer)Activator.CreateInstance(m_startingLayerType)); } WorldTick = 0; }
public void UseMoveOnAllies(BattleSetup setup, TargetCollection targets) { //List<ICharacter> targets = MoveProcessor.GetTargetsInRange(setup.Move.RangeType, setup.Move.Range, setup.AttackerMap, this, X, Y, Direction); Move move = setup.SetdownMove(); foreach (ICharacter i in targets.Friends) { if (i.CharacterType == Enums.CharacterType.MapNpc && ((MapNpc)i).Num <= 0) { } else { setup.Defender = i; BattleProcessor.MoveHitCharacter(setup); setup.SetupMove(move); if (setup.Cancel) { return; } } } }
public void UseMoveOnAllies(BattleSetup setup, TargetCollection targets) { Parties.Party party = null; if (owner.Player.IsInParty()) { party = Parties.PartyManager.FindPlayerParty(owner); } //List<ICharacter> targets = MoveProcessor.GetTargetsInRange(setup.Move.RangeType, setup.Move.Range, setup.AttackerMap, this, owner.Player.X, owner.Player.Y, owner.Player.Direction); Move move = setup.SetdownMove(); // Attack any players that are on the map foreach (ICharacter i in targets.Friends) { if (i.CharacterType == Enums.CharacterType.Recruit && !((Recruit)i).Owner.Player.Dead) { var recruit = i as Recruit; if (setup.moveIndex == -1) { if (setup.AttackerMap.Moral == Enums.MapMoral.Safe || setup.AttackerMap.Moral == Enums.MapMoral.House) { Scripting.ScriptManager.InvokeSub("InteractWithPlayer", Owner, recruit.Owner); } } } else { setup.Defender = i; BattleProcessor.MoveHitCharacter(setup); setup.SetupMove(move); if (setup.Cancel) { return; } } } }
public void ProcessAI() { try { TickCount tickCount = Core.GetTickCount(); PacketHitList packetList = null; PacketHitList.MethodStart(ref packetList); if (map.IsSaving == false) { // Keys/Other timed tile stuff for (int x = 0; x <= map.MaxX; x++) { for (int y = 0; y <= map.MaxY; y++) { if (map.Tile[x, y] != null) { if (tickCount.Elapsed(map.Tile[x, y].DoorTimer, 5000)) { if ((map.Tile[x, y].Type == Enums.TileType.Key || map.Tile[x, y].Type == Enums.TileType.Door) && map.Tile[x, y].DoorOpen == true) { map.Tile[x, y].DoorOpen = false; packetList.AddPacketToMap(map, TcpPacket.CreatePacket("mapkey", x.ToString(), y.ToString(), "0")); } } } } } Scripting.ScriptManager.InvokeSub("OnMapTick", map); if (map.ProcessingPaused == false) { int livingNpcs = 0; for (int mapNpcSlot = 0; mapNpcSlot < Constants.MAX_MAP_NPCS; mapNpcSlot++) { int npcNum = map.ActiveNpc[mapNpcSlot].Num; MapNpc mapNpc = map.ActiveNpc[mapNpcSlot]; if (npcNum > 0) { livingNpcs++; Npc npc = NpcManager.Npcs[npcNum]; if (npc.Behavior != Enums.NpcBehavior.FullyScriptedAI || npc.AIScript == "" || npc.AIScript.ToLower() == "none") { #region Used for attacking on sight if (npc.Behavior == Enums.NpcBehavior.AttackOnSight || npc.Behavior == Enums.NpcBehavior.Guard) { foreach (Client i in map.GetClients()) { if (i.Player.MapID == map.MapID && map.ActiveNpc[mapNpcSlot].Target == null && !i.Player.Dead && i.Player.Hunted && map.Tile[i.Player.X, i.Player.Y].Type != Enums.TileType.NPCAvoid && i.Player.Hunted) { if (MovementProcessor.CanCharacterSeeCharacter(map, map.ActiveNpc[mapNpcSlot], i.Player.GetActiveRecruit())) { if (npc.Behavior == Enums.NpcBehavior.AttackOnSight /* || i.Player.PK == true*/) { //if (!string.IsNullOrEmpty(npc.AttackSay)) { // packetList.AddPacket(i, PacketBuilder.CreateChatMsg("A " + npc.Name + " : " + npc.AttackSay, Text.Grey)); //} map.ActiveNpc[mapNpcSlot].Target = i; } } } } } #endregion #region Used for walking/targetting/picking up items if (npcNum > 0) { bool hasNpcWalked; if (map.ActiveNpc[mapNpcSlot].Target != null && map.ActiveNpc[mapNpcSlot].Target.IsPlaying() && map.ActiveNpc[mapNpcSlot].Target.Player.MapID == map.MapID && (map.Tile[map.ActiveNpc[mapNpcSlot].Target.Player.X, map.ActiveNpc[mapNpcSlot].Target.Player.Y].Type == Enums.TileType.NPCAvoid || !map.ActiveNpc[mapNpcSlot].Target.Player.Hunted || map.ActiveNpc[mapNpcSlot].Target.Player.Dead || !MovementProcessor.CanCharacterSeeCharacter(map, map.ActiveNpc[mapNpcSlot], map.ActiveNpc[mapNpcSlot].Target.Player.GetActiveRecruit()))) { map.ActiveNpc[mapNpcSlot].Target = null; } Client target = map.ActiveNpc[mapNpcSlot].Target; if (npc.Behavior != Enums.NpcBehavior.Shopkeeper) { if (target != null) { if (target.IsPlaying() && target.Player.MapID == map.MapID) { hasNpcWalked = false; int dir = Math.Rand(0, 5); hasNpcWalked = AIProcessor.MoveNpcInDirection((Enums.Direction)dir, map, target, packetList, mapNpcSlot); if (!hasNpcWalked) { foreach (Enums.Direction direction in Enum.GetValues(typeof(Enums.Direction))) { if (direction != (Enums.Direction)dir) { if (AIProcessor.MoveNpcInDirection(direction, map, target, packetList, mapNpcSlot)) { break; } } } } if (hasNpcWalked == false) { if (map.ActiveNpc[mapNpcSlot].X - 1 == target.Player.X && map.ActiveNpc[mapNpcSlot].Y == target.Player.Y) { if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Left) { MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Left); } hasNpcWalked = true; } if (map.ActiveNpc[mapNpcSlot].X + 1 == target.Player.X && map.ActiveNpc[mapNpcSlot].Y == target.Player.Y) { if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Right) { MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Right); } hasNpcWalked = true; } if (map.ActiveNpc[mapNpcSlot].X == target.Player.X && map.ActiveNpc[mapNpcSlot].Y - 1 == target.Player.Y) { if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Up) { MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Up); } hasNpcWalked = true; } if (map.ActiveNpc[mapNpcSlot].X == target.Player.X && map.ActiveNpc[mapNpcSlot].Y + 1 == target.Player.Y) { if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Down) { MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Down); } hasNpcWalked = true; } } if (hasNpcWalked == false) { int val = Math.Rand(0, 2); if (val == 1) { val = Math.Rand(0, 4); if (MovementProcessor.CanNpcMove(map, mapNpcSlot, (Enums.Direction)val)) { MovementProcessor.NpcMove(packetList, map, mapNpcSlot, map.ActiveNpc[mapNpcSlot].Direction, Enums.Speed.Walking); } } } } else { map.ActiveNpc[mapNpcSlot].Target = null; } } else { int shouldWalk = Math.Rand(0, 2); if (npc.Behavior != Enums.NpcBehavior.Friendly) { for (int i = 0; i < Constants.MAX_MAP_ITEMS; i++) { if (map.ActiveItem[i].X == map.ActiveNpc[mapNpcSlot].X && map.ActiveItem[i].Y == map.ActiveNpc[mapNpcSlot].Y && map.ActiveItem[i].Num > -1 && map.ActiveNpc[mapNpcSlot].HeldItem == null) { map.ActiveNpc[mapNpcSlot].MapGetItem(); shouldWalk = 1; } } } else if (npc.Behavior == Enums.NpcBehavior.Friendly) { foreach (Client i in map.GetClients()) { if (i.Player.X >= map.ActiveNpc[mapNpcSlot].X - 1 && i.Player.X <= map.ActiveNpc[mapNpcSlot].X + 1 && i.Player.Y >= map.ActiveNpc[mapNpcSlot].Y - 1 && i.Player.Y <= map.ActiveNpc[mapNpcSlot].Y + 1) { shouldWalk = Math.Rand(0, 10); break; } } } if (shouldWalk == 0) { shouldWalk = Math.Rand(0, 5); if (MovementProcessor.CanNpcMove(map, mapNpcSlot, (Enums.Direction)shouldWalk)) { MovementProcessor.NpcMove(packetList, map, mapNpcSlot, map.ActiveNpc[mapNpcSlot].Direction, Enums.Speed.Walking); } } } } } #endregion #region Used for attacking players if (npcNum > 0) { Client target = map.ActiveNpc[mapNpcSlot].Target; if (target != null) { if (target.IsPlaying() && target.Player.MapID == map.MapID) { // Make sure npcs dont attack more then once a second if (Core.GetTickCount().Elapsed(map.ActiveNpc[mapNpcSlot].AttackTimer, 1000)) { int usableMoveCount = 0; for (int i = 0; i < mapNpc.Moves.Length; i++) { if (mapNpc.Moves[i].MoveNum > -1 && mapNpc.Moves[i].CurrentPP > 0) { usableMoveCount++; } } if (usableMoveCount == 0) { if (BattleProcessor.ShouldUseMove(map, mapNpc, -1)) { mapNpc.UseMove(-1); } } else { // Try to use a move, up to 50 times for (int i = 0; i < 50; i++) { int moveSlotToUse = Server.Math.Rand(0, 5) - 1; if (moveSlotToUse == -1) { // A standard attack if (BattleProcessor.ShouldUseMove(map, mapNpc, moveSlotToUse)) { mapNpc.UseMove(moveSlotToUse); break; } } else { if (mapNpc.Moves[moveSlotToUse].MoveNum > -1 && mapNpc.Moves[moveSlotToUse].CurrentPP > 0) { // Use a move if (BattleProcessor.ShouldUseMove(map, mapNpc, moveSlotToUse)) { mapNpc.UseMove(moveSlotToUse); break; } } } } } } } else { map.ActiveNpc[mapNpcSlot].Target = null; } } } #endregion if (npcNum > 0 && map.ActiveNpc[mapNpcSlot].HPChanged) { map.ActiveNpc[mapNpcSlot].SendHPToMap(packetList, map, mapNpcSlot); } } else { // Scripted AI: Reimplement? //Globals.AIScriptManager.CallAIProcessSub(NpcManager.Npcs[map.Npc[x].NpcNum].AIScript, tickCount, map.MapNum, x); } } } //try and spawn something if (map.NpcSpawnWait == null) { map.NpcSpawnWait = Core.GetTickCount(); } if (Core.GetTickCount().Tick > map.NpcSpawnWait.Tick) { if (livingNpcs < map.MaxNpcs) { map.SpawnNpc(true); } map.NpcSpawnWait = new TickCount(map.NpcSpawnWait.Tick + map.NpcSpawnTime * 1000); } } } //lock (MapManager.ActiveMapLockObject) { bool shouldRemove = false; if (map.PlayersOnMap.Count == 0 && tickCount.Elapsed(map.ActivationTime, AIProcessor.MapTTL)) { if (map.IsProcessingComplete()) { shouldRemove = true; for (int i = 1; i < 9; i++) { IMap borderingMap = MapManager.RetrieveActiveBorderingMap(map, (Enums.MapID)i); if (borderingMap != null) { if (borderingMap.PlayersOnMap.Count > 0) { shouldRemove = false; } } } if (shouldRemove) { MapManager.rwLock.EnterWriteLock(); try { if (map.MapType == Enums.MapType.House) { // Only save the map here when logging out - otherwise, the map is saved when the player is saved map.Save(); } if ((map.MapType == Enums.MapType.RDungeonMap || map.MapType == Enums.MapType.Instanced)) { using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { if (MapManager.GetTotalPlayersOnMap(dbConnection, map.MapID) == 0) { DataManager.Maps.MapDataManager.DeleteMap(dbConnection.Database, map.MapID); } else { map.Save(); } } } MapManager.UnsafeRemoveActiveMap(map.MapID); } finally { MapManager.rwLock.ExitWriteLock(); } } } } //} PacketHitList.MethodEnded(ref packetList); } catch (Exception ex) { Server.Exceptions.ErrorLogger.WriteToErrorLog(ex, "MapAIProcessor"); } }
public void UseMoveOnFoes(BattleSetup setup, TargetCollection targets) { Parties.Party party = null; if (owner.Player.IsInParty()) { party = Parties.PartyManager.FindPlayerParty(owner); } //List<ICharacter> targets = MoveProcessor.GetTargetsInRange(setup.Move.RangeType, setup.Move.Range, setup.AttackerMap, this, owner.Player.X, owner.Player.Y, owner.Player.Direction); Move move = setup.SetdownMove(); foreach (ICharacter i in targets.Foes) { // Don't attack allies if (i.CharacterType == Enums.CharacterType.Recruit) { Recruit recruit = i as Recruit; var canHit = true; if (Ranks.IsAllowed(recruit.Owner, Enums.Rank.Monitor) && !recruit.Owner.Player.Hunted) { canHit = false; } if ((recruit.Owner.Player.Map.Tile[recruit.Owner.Player.X, recruit.Owner.Player.Y].Type == Enums.TileType.Arena) != (Owner.Player.Map.Tile[X, Y].Type == Enums.TileType.Arena)) { canHit = false; } // Override to allow hitting the player ANYWHERE if (recruit.Owner.Player.KillableAnywhere) { canHit = true; } if (canHit) { setup.Defender = i; BattleProcessor.MoveHitCharacter(setup); setup.SetupMove(move); if (setup.Cancel) { return; } } } else if (i.CharacterType == Enums.CharacterType.MapNpc && (((MapNpc)i).Num <= 0 || ((MapNpc)i).HP <= 0)) { } else if (i.CharacterType == Enums.CharacterType.MapNpc) { MapNpc npc = i as MapNpc; if (Npcs.NpcManager.Npcs[npc.Num].Behavior == Enums.NpcBehavior.Scripted) { if (setup.moveIndex == -1) { Scripting.ScriptManager.InvokeSub("ScriptedNpc", setup.Attacker, Npcs.NpcManager.Npcs[npc.Num].AIScript, npc.Num, owner.Player.Map, i); } } else if (Npcs.NpcManager.Npcs[npc.Num].Behavior == Enums.NpcBehavior.Story) { if (setup.moveIndex == -1) { var npcObject = Npcs.NpcManager.Npcs[npc.Num]; var storyChapter = npcObject.Story - 1; if (storyChapter <= -1 || owner.Player.GetStoryState(storyChapter)) { Stories.StoryManager.PlayStory(owner, Npcs.NpcManager.Npcs[npc.Num].CreateAttackSayStory()); } else { if (owner.Player.GetClientEdition() == Constants.ALTERNATE_CLIENT_EDITION) { Stories.StoryManager.PlayStory(owner, storyChapter); } else { Stories.StoryManager.PlayStory(owner, Npcs.NpcManager.Npcs[npc.Num].CreateInvalidClientStory()); } } } } else if (Npcs.NpcManager.Npcs[npc.Num].Behavior == Enums.NpcBehavior.Shopkeeper && Npcs.NpcManager.Npcs[npc.Num].Shop > 0) { if (setup.moveIndex == -1) { Messenger.SendShopMenu(owner, Npcs.NpcManager.Npcs[npc.Num].Shop); } } else if (!string.IsNullOrEmpty(Npcs.NpcManager.Npcs[npc.Num].AttackSay) && (Npcs.NpcManager.Npcs[npc.Num].Behavior == Enums.NpcBehavior.Friendly || Npcs.NpcManager.Npcs[npc.Num].Behavior == Enums.NpcBehavior.Shopkeeper)) { if (setup.moveIndex == -1) { var story = Npcs.NpcManager.Npcs[npc.Num].CreateAttackSayStory(); Stories.StoryManager.PlayStory(owner, story); } } else { setup.Defender = i; BattleProcessor.MoveHitCharacter(setup); setup.SetupMove(move); if (setup.Cancel) { return; } } } else { setup.Defender = i; BattleProcessor.MoveHitCharacter(setup); setup.SetupMove(move); if (setup.Cancel) { return; } } } }
public void UseMoveOnFoes(BattleSetup setup, TargetCollection targets) { Parties.Party party = null; if (owner.Player.IsInParty()) { party = Parties.PartyManager.FindPlayerParty(owner); } //List<ICharacter> targets = MoveProcessor.GetTargetsInRange(setup.Move.RangeType, setup.Move.Range, setup.AttackerMap, this, owner.Player.X, owner.Player.Y, owner.Player.Direction); Move move = setup.SetdownMove(); foreach (ICharacter i in targets.Foes) { // Don't attack allies if (i.CharacterType == Enums.CharacterType.Recruit) { Recruit recruit = i as Recruit; if (Ranks.IsAllowed(recruit.Owner, Enums.Rank.Moniter) && !recruit.Owner.Player.Hunted || (recruit.Owner.Player.Map.Tile[recruit.Owner.Player.X, recruit.Owner.Player.Y].Type == Enums.TileType.Arena) != (Owner.Player.Map.Tile[X, Y].Type == Enums.TileType.Arena)) { } else { setup.Defender = i; BattleProcessor.MoveHitCharacter(setup); setup.SetupMove(move); if (setup.Cancel) { return; } } } else if (i.CharacterType == Enums.CharacterType.MapNpc && (((MapNpc)i).Num <= 0 || ((MapNpc)i).HP <= 0)) { } else if (i.CharacterType == Enums.CharacterType.MapNpc) { MapNpc npc = i as MapNpc; if (Npcs.NpcManager.Npcs[npc.Num].Behavior == Enums.NpcBehavior.Scripted) { if (setup.moveIndex == -1) { Scripting.ScriptManager.InvokeSub("ScriptedNpc", setup.Attacker, Npcs.NpcManager.Npcs[npc.Num].AIScript, npc.Num, owner.Player.Map, i); } } else if (!string.IsNullOrEmpty(Npcs.NpcManager.Npcs[npc.Num].AttackSay) && (Npcs.NpcManager.Npcs[npc.Num].Behavior == Enums.NpcBehavior.Friendly || Npcs.NpcManager.Npcs[npc.Num].Behavior == Enums.NpcBehavior.Shopkeeper)) { if (setup.moveIndex == -1) { Stories.Story story = new Stories.Story(); Stories.StoryBuilderSegment segment = Stories.StoryBuilder.BuildStory(); Stories.StoryBuilder.AppendSaySegment(segment, Npcs.NpcManager.Npcs[npc.Num].Name.Trim() + ": " + Npcs.NpcManager.Npcs[npc.Num].AttackSay.Trim(), Npcs.NpcManager.Npcs[npc.Num].Species, 0, 0); segment.AppendToStory(story); Stories.StoryManager.PlayStory(owner, story); } } else { setup.Defender = i; BattleProcessor.MoveHitCharacter(setup); setup.SetupMove(move); if (setup.Cancel) { return; } } } else { setup.Defender = i; BattleProcessor.MoveHitCharacter(setup); setup.SetupMove(move); if (setup.Cancel) { return; } } } }