/// <summary> /// Initializes a new instance of the <see cref="Gamemap" /> class. /// </summary> /// <param name="room">The room.</param> /// <exception cref="System.Exception"></exception> public Gamemap(Room room) { _room = room; DiagonalEnabled = true; StaticModel = Azure.GetGame().GetRoomManager().GetModel(room.RoomData.ModelName, room.RoomId); if (StaticModel == null) throw new ArgumentNullException($"No modeldata found for roomID {room.RoomId}"); Model = new DynamicRoomModel(StaticModel, room); CoordinatedItems = new HybridDictionary(); GotPublicPool = room.RoomData.Model.GotPublicPool; GameMap = new byte[Model.MapSizeX, Model.MapSizeY]; ItemHeightMap = new double[Model.MapSizeX, Model.MapSizeY]; _userMap = new HybridDictionary(); WalkableList = GetWalkablePoints(); GuildGates = new Dictionary<Point, RoomItem>(); }
public static RoomUser DeployBotByID(int RoleplayBotsID, string SpawnType = "default", int RoomID = 0) { lock (SyncLock) { try { if (!RoleplayBotManager.CachedRoleplayBots.ContainsKey(RoleplayBotsID)) { return(null); } #region If the bot already exists simply transfer it RoleplayBot DeployingBot = RoleplayBotManager.CachedRoleplayBots[RoleplayBotsID]; if (DeployingBot.DRoomUser != null) { if (DeployingBot.DRoom != null) { if (DeployingBot.DRoom.Id != RoomID) { RoleplayBotManager.TransportDeployedBot(DeployingBot.DRoomUser, (RoomID == 0 ? DeployingBot.SpawnId : RoomID)); } } return(null); } #endregion Room RoleplayBotsRoom; if (RoomID == 0) { if (RoleplayManager.GenerateRoom(DeployingBot.SpawnId, false) == null) { return(null); } else { RoleplayBotsRoom = RoleplayManager.GenerateRoom(DeployingBot.SpawnId, false); } } else { if (RoleplayManager.GenerateRoom(RoomID, false) == null) { return(null); } else { RoleplayBotsRoom = RoleplayManager.GenerateRoom(RoomID, false); } DeployingBot.SpawnId = RoleplayBotsRoom.RoomId; } #region Misc variables RoomUserManager RoomManager = RoleplayBotsRoom.GetRoomUserManager(); RoomUser BotsRoomUserInstance = new RoomUser(0, RoleplayBotsRoom.RoomId, RoomManager.primaryPrivateUserID++, RoleplayBotsRoom); List <RandomSpeech> BotsSpeech = new List <RandomSpeech>(); int BotsPersonalID = RoomManager.secondaryPrivateUserID++; BotsRoomUserInstance.InternalRoomID = BotsPersonalID; RoomManager._users.TryAdd(BotsPersonalID, BotsRoomUserInstance); DynamicRoomModel RoleplayBotsModel = RoleplayBotsRoom.GetGameMap().Model; #endregion #region Spawning & Positioning if (DeployingBot.Dead) { RoleplayManager.SpawnBeds(null, "hosptl_bed", BotsRoomUserInstance); } else { #region Spawn at origin if (SpawnType == "default") { if ((DeployingBot.X > 0 && DeployingBot.Y > 0) && DeployingBot.X < RoleplayBotsModel.MapSizeX && DeployingBot.Y < RoleplayBotsModel.MapSizeY) { BotsRoomUserInstance.SetPos(DeployingBot.X, DeployingBot.Y, DeployingBot.Z); BotsRoomUserInstance.SetRot(DeployingBot.SpawnRot, false); } else { DeployingBot.X = RoleplayBotsModel.DoorX; DeployingBot.Y = RoleplayBotsModel.DoorY; BotsRoomUserInstance.SetPos(RoleplayBotsModel.DoorX, RoleplayBotsModel.DoorY, RoleplayBotsModel.DoorZ); BotsRoomUserInstance.SetRot(RoleplayBotsModel.DoorOrientation, false); } } #endregion #region Spawn at work item if (SpawnType == "workitem") { Item Item; if (DeployingBot.GetStopWorkItem(RoleplayBotsRoom, out Item)) { var Point = new Point(Item.GetX, Item.GetY); BotsRoomUserInstance.X = Point.X; BotsRoomUserInstance.Y = Point.Y; BotsRoomUserInstance.SetPos(Point.X, Point.Y, RoleplayBotsRoom.GetGameMap().GetHeightForSquare(Point)); BotsRoomUserInstance.SetRot(Item.Rotation, false); } else { BotsRoomUserInstance.X = RoleplayBotsModel.DoorX; BotsRoomUserInstance.Y = RoleplayBotsModel.DoorY; BotsRoomUserInstance.SetPos(RoleplayBotsModel.DoorX, RoleplayBotsModel.DoorY, RoleplayBotsModel.DoorZ); BotsRoomUserInstance.SetRot(RoleplayBotsModel.DoorOrientation, false); } } #endregion #region Spawn at owner if (SpawnType == "owner" && DeployingBot.Owner != null) { RoomUser OwnerInstance = DeployingBot.Owner.GetRoomUser(); int X = OwnerInstance.SquareInFront.X; int Y = OwnerInstance.SquareInFront.Y; double Z = OwnerInstance.Z; if ((OwnerInstance != null) && (X > 0 && Y > 0) && X < RoleplayBotsModel.MapSizeX && Y < RoleplayBotsModel.MapSizeY) { BotsRoomUserInstance.SetPos(X, Y, Z); BotsRoomUserInstance.SetRot(DeployingBot.SpawnRot, false); } else { X = OwnerInstance.X; Y = OwnerInstance.Y; DeployingBot.X = X; DeployingBot.Y = Y; BotsRoomUserInstance.SetPos(X, Y, OwnerInstance.Z); BotsRoomUserInstance.SetRot(DeployingBot.SpawnRot, false); } } #endregion } #endregion #region Generate Roleplay Bot's data, timers BotsRoomUserInstance.BotData = new RoomBot(DeployingBot.Id, DeployingBot.SpawnId, DeployingBot.AITypeString, "stand", DeployingBot.Name, "Motto", DeployingBot.Figure, DeployingBot.X, DeployingBot.Y, DeployingBot.Z, DeployingBot.SpawnRot, DeployingBot.X, DeployingBot.Y, DeployingBot.X, DeployingBot.Y, ref BotsSpeech, DeployingBot.Gender, 0, 0, false, 0, false, 0); BotsRoomUserInstance.RPBotAI = RoleplayBotManager.GetRoleplayBotAI(DeployingBot.AIType, BotsRoomUserInstance.VirtualId); BotsRoomUserInstance.BotAI = BotsRoomUserInstance.BotData.GenerateBotAI(BotsRoomUserInstance.VirtualId); if (DeployingBot.IsPet) { BotsRoomUserInstance.PetData = DeployingBot.PetInstance; BotsRoomUserInstance.PetData.VirtualId = BotsRoomUserInstance.VirtualId; } BotsRoomUserInstance.RPBotAI.Init(DeployingBot.Id, DeployingBot, BotsRoomUserInstance.VirtualId, DeployingBot.SpawnId, BotsRoomUserInstance, RoleplayBotsRoom); BotsRoomUserInstance.BotAI.Init(DeployingBot.Id, BotsRoomUserInstance.VirtualId, DeployingBot.SpawnId, BotsRoomUserInstance, RoleplayBotsRoom); if (DeployingBot.TimerManager == null) { DeployingBot.TimerManager = new BotTimerManager(DeployingBot); } else { DeployingBot.TimerManager.CachedBot = DeployingBot; } if (DeployingBot.CooldownManager == null) { DeployingBot.CooldownManager = new BotCooldownManager(DeployingBot); } else { DeployingBot.CooldownManager.CachedBot = DeployingBot; } RoomManager.UpdateUserStatus(BotsRoomUserInstance, false); BotsRoomUserInstance.UpdateNeeded = true; #region Set general variables DeployingBot.Teleporting = false; DeployingBot.TeleporterEntering = null; DeployingBot.TeleporterExiting = null; DeployingBot.Teleported = false; DeployingBot.Deployed = true; DeployingBot.RoomStayTime = new CryptoRandom().Next(0, DeployingBot.RoomStayInterval); DeployingBot.FollowCooldown = new CryptoRandom().Next(0, DeployingBot.FollowInterval); DeployingBot.AttackCooldown = new CryptoRandom().Next(0, DeployingBot.AttackInterval); DeployingBot.RoamCooldown = new CryptoRandom().Next(0, DeployingBot.RoamInterval); DeployingBot.RoomStayTime = new CryptoRandom().Next(0, DeployingBot.RoomStayInterval); DeployingBot.LookCooldown = new CryptoRandom().Next(0, DeployingBot.LookCooldown); #endregion #endregion #region Compose Roleplay Bot's visibility & insert into deployed bots DeployingBot.Invisible = false; if (!DeployingBot.Invisible) { RoleplayBotsRoom.SendMessage(new UsersComposer(BotsRoomUserInstance)); } if (RoomManager._bots.ContainsKey(DeployingBot.Id)) { RoomManager._bots[DeployingBot.Id] = BotsRoomUserInstance; } else { RoomManager._bots.TryAdd(DeployingBot.Id, BotsRoomUserInstance); } RoleplayBotsRoom.SendMessage(new DanceComposer(BotsRoomUserInstance, 0)); #endregion #region Attach RoleplayBot Instance to RoomUser & deliver its respective data BotsRoomUserInstance.RPBotData = DeployingBot; if (!RoleplayBotManager.DeployedRoleplayBots.ContainsKey(DeployingBot.Id)) { RoleplayBotManager.DeployedRoleplayBots.TryAdd(DeployingBot.Id, BotsRoomUserInstance); } else { RoomUser NullBot; RoleplayBotManager.ClearRoleplayBotClones(DeployingBot.Id); RoleplayBotManager.DeployedRoleplayBots.TryAdd(DeployingBot.Id, BotsRoomUserInstance); } #region Start roaming if (DeployingBot.RoamBot) { DeployingBot.MoveRandomly(); } #endregion DeployingBot.DRoomUser.GetBotRoleplayAI().OnDeployed(DeployingBot.Owner); #endregion return(BotsRoomUserInstance); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(null); }