private static void GetPetInfo(Session Session, ClientMessage Message) { RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null) { return; } uint ActorRefId = Message.PopWiredUInt32(); RoomActor Actor = Instance.GetActorByReferenceId(ActorRefId, RoomActorType.AiBot); if (Actor == null) { return; } Pet PetData = ((Bot)Actor.ReferenceObject).PetData; if (PetData == null) { return; } Session.SendData(PetInfoComposer.Compose(Actor.ReferenceId, PetData)); }
private static void UserDance(Session Session, ClientMessage Message) { RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null) { return; } RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId); if (Actor == null || Actor.AvatarEffectId > 0) { return; } int DanceId = Message.PopWiredInt32(); if (DanceId < 0 || DanceId > 4) { return; } if (!Session.HasRight("club_regular") && !Session.HasRight("club_vip") && DanceId != 0) { DanceId = 1; } Actor.Dance(DanceId); QuestManager.ProgressUserQuest(Session, QuestType.SOCIAL_DANCE); }
private static void TakePet(Session Session, ClientMessage Message) { RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null) { return; } RoomActor Actor = Instance.GetActorByReferenceId(Message.PopWiredUInt32(), RoomActorType.AiBot); if (Actor == null) { return; } Pet PetData = ((Bot)Actor.ReferenceObject).PetData; if (PetData == null || (PetData.OwnerId != Session.CharacterId && !Session.HasRight("hotel_admin"))) { return; } Instance.RemoveActorFromRoom(Actor.Id); Session.PetInventoryCache.Add(PetData); Session.SendData(InventoryPetAddedComposer.Compose(PetData)); }
private bool AddActorToRoom(RoomActor Actor) { lock (mActorSyncRoot) { if (mActors.ContainsKey(Actor.Id)) { return(false); } mActors.Add(Actor.Id, Actor); BroadcastMessage(RoomUserObjectListComposer.Compose(new List <RoomActor>() { Actor })); MarkActorCountSyncNeeded(); foreach (RoomActor _Actor in mActors.Values) { if (_Actor.Type == RoomActorType.AiBot) { if (_Actor.Id == Actor.Id) { ((Bot)_Actor.ReferenceObject).Brain.OnSelfEnterRoom(this); } else { ((Bot)_Actor.ReferenceObject).Brain.OnUserEnter(this, Actor); } } } return(true); } }
public override void OnUserChat(RoomInstance Instance, RoomActor Actor, string MessageText, bool Shout) { if (mSelfActor == null || Actor.Type == RoomActorType.AiBot || mServingItemId > 0 || (Distance.Calculate(Actor.Position.GetVector2(), mSelfActor.Position.GetVector2()) > mSelfBot.ResponseDistance)) { return; } BotResponse Response = mSelfBot.GetResponseForMessage(MessageText); if (Response != null) { mSelfActor.Chat(Response.GetResponse(), false); if (Response.ResponseServeId > 0) { mMovingToServePos = true; mServingItemId = Response.ResponseServeId; mServingActorId = Actor.Id; mActorServePos = new Vector2(mSelfActor.Position.X, mSelfActor.Position.Y); mSelfActor.MoveTo(mSelfBot.ServePosition); if (mNextMovementAttempt < 50) { mNextMovementAttempt = 50; } } if (mNextSpeechAttempt < 50) { mNextSpeechAttempt += 10; } } }
public void BanUser(uint UserId) { lock (mActorSyncRoot) { RoomActor Actor = GetActorByReferenceId(UserId); if (Actor == null || Actor.Type != RoomActorType.UserCharacter) { return; } Session ActorSession = SessionManager.GetSessionByCharacterId(Actor.ReferenceId); if (ActorSession != null) { if (CheckUserRights(ActorSession, true)) { return; // this is the room owner or a moderator, no banning allowed on this guy! } } double Timestamp = UnixTimestamp.GetCurrent(); if (mBannedUsers.ContainsKey(UserId)) { mBannedUsers[UserId] = Timestamp; return; } mBannedUsers.Add(UserId, Timestamp); } SoftKickUser(UserId, true); }
public void SoftKickUser(uint UserId, bool Forced = false, bool NotifyUser = false, bool OverrideOwner = false) { RoomActor Actor = GetActorByReferenceId(UserId); if (Actor == null || Actor.Type != RoomActorType.UserCharacter) { return; } Session ActorSession = SessionManager.GetSessionByCharacterId(Actor.ReferenceId); if (ActorSession != null) { if (!OverrideOwner && CheckUserRights(ActorSession, true)) { return; // this is the room owner or a moderator, no kicking allowed! } if (NotifyUser) { ActorSession.SendData(GenericErrorComposer.Compose(4008)); } } Actor.LeaveRoom(Forced); }
private static void UserMoveTo(Session Session, ClientMessage Message) { RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null) { return; } RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId); if (Actor == null) { return; } int RequestX = Message.PopWiredInt32(); int RequestY = Message.PopWiredInt32(); if (RequestX < 0 || RequestY < 0) { return; } Actor.MoveTo(new Vector2(RequestX, RequestY)); }
public void Whisper(string MessageText, uint TargetUserId, bool CanOverrideRoomMute = false) { if (mIsLeavingRoom && mForcedLeave) { return; } Unidle(); if (mInstance.RoomMuted && !CanOverrideRoomMute) { return; } ServerMessage Message = RoomChatComposer.Compose(Id, MessageText, 0, ChatType.Whisper); if (Type == RoomActorType.UserCharacter) { Session Session = SessionManager.GetSessionByCharacterId(mReferenceId); if (Session != null) { Session.SendData(Message); } } string LogTargetName = "Unknown User"; if (TargetUserId != mReferenceId) { RoomActor TargetActor = mInstance.GetActorByReferenceId(TargetUserId); if (TargetActor == null || TargetActor.Type != RoomActorType.UserCharacter) { return; } Session TargetSession = SessionManager.GetSessionByCharacterId(TargetActor.ReferenceId); if (TargetSession != null) { if (!TargetSession.IgnoreCache.UserIsIgnored(this.ReferenceId)) { TargetSession.SendData(Message); } LogTargetName = TargetSession.CharacterInfo.Username; } } if (mType == RoomActorType.UserCharacter) { using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { ModerationLogs.LogChatMessage(MySqlClient, mReferenceId, mInstance.RoomId, "(Whisper to " + LogTargetName + ") " + MessageText); IncrecementAntiSpam(MySqlClient); } } }
public override void OnSelfLeaveRoom(RoomInstance Instance) { if (mSelfActor == null) { return; } mSelfActor = null; }
private static void UserChat(Session Session, ClientMessage Message) { if (Session.CharacterInfo.IsMuted) { return; } RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null) { return; } RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId); if (Actor == null) { return; } bool Shout = (Message.Id == OpcodesIn.ROOM_CHAT_SHOUT); string MessageText = UserInputFilter.FilterString(Message.PopString()); if (MessageText.Length == 0) { return; } if (MessageText.Length > 100) { MessageText = MessageText.Substring(0, 100); } MessageText = Wordfilter.Filter(MessageText); if (MessageText.StartsWith(":") && (ChatCommands.HandleCommand(Session, MessageText) || Session.HasRight("moderation_tool"))) { return; } if (Instance.WiredManager.HandleChat(MessageText, Actor)) { Actor.Whisper(MessageText, 0); return; } Actor.Chat(MessageText, Shout, Session.HasRight("mute")); if (Instance.HumanActorCount > 1) { QuestManager.ProgressUserQuest(Session, QuestType.SOCIAL_CHAT); } }
private static void UserWhisper(Session Session, ClientMessage Message) { if (Session.CharacterInfo.IsMuted) { return; } RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null) { return; } RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId); if (Actor == null) { return; } string MessageText = UserInputFilter.FilterString(Message.PopString().Trim()); if (MessageText.Length == 0) { return; } if (MessageText.Length > 100) { MessageText = MessageText.Substring(0, 100); } string[] Bits = MessageText.Split(' '); if (Bits.Length < 2) { return; } string UserBit = Bits[0]; MessageText = MessageText.Substring(UserBit.Length + 1); uint UserId = CharacterResolverCache.GetUidFromName(UserBit); if (UserId > 0) { Actor.Whisper(MessageText, UserId); } }
public void HardKickUser(uint UserId) { RoomActor Actor = GetActorByReferenceId(UserId); if (Actor == null || Actor.Type != RoomActorType.UserCharacter) { return; } Session ActorSession = SessionManager.GetSessionByCharacterId(Actor.ReferenceId); RoomManager.RemoveUserFromRoom(ActorSession, true); RemoveCharacterFromRoom(UserId); }
public void KickBot(uint ActorId) { RoomActor Actor = GetActor(ActorId); if (Actor == null || Actor.Type != RoomActorType.AiBot) { return; } Bot Bot = (Bot)Actor.ReferenceObject; if (Bot == null || !Bot.Kickable) { return; } RemoveActorFromRoom(ActorId); }
private static void UserExit(Session Session, ClientMessage Message) { RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null) { return; } RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId); if (Actor == null) { return; } Actor.LeaveRoom(); }
private static void TypingStateChanged(Session Session, ClientMessage Message) { RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null) { return; } RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId); if (Actor == null) { return; } Actor.SetTypingState((Message.Id == OpcodesIn.ROOM_CHAT_START_TYPING)); }
private static void UserWave(Session Session, ClientMessage Message) { RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null) { return; } RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId); if (Actor == null || Actor.AvatarEffectId > 0) { return; } Actor.Wave(); QuestManager.ProgressUserQuest(Session, QuestType.SOCIAL_WAVE); }
private static void GetUserTags(Session Session, ClientMessage Message) { RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null) { return; } RoomActor Actor = Instance.GetActorByReferenceId(Message.PopWiredUInt32()); if (Actor == null) { return; } CharacterInfo Info = (CharacterInfo)Actor.ReferenceObject; Session.SendData(RoomUserTagsComposer.Compose(Info.Id, Info.Tags)); }
private static void RespectUser(Session Session, ClientMessage Message) { RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null || Session.CharacterInfo.RespectCreditHuman <= 0) { return; } RoomActor TargetActor = Instance.GetActorByReferenceId(Message.PopWiredUInt32()); if (TargetActor == null) { return; } Session TargetSession = SessionManager.GetSessionByCharacterId(TargetActor.ReferenceId); if (TargetSession == null) { return; } TargetSession.CharacterInfo.RespectPoints++; Session.CharacterInfo.RespectCreditHuman--; Instance.BroadcastMessage(RoomUserRespectedComposer.Compose(TargetSession.CharacterId, TargetSession.CharacterInfo.RespectPoints)); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { TargetSession.CharacterInfo.SynchronizeRespectData(MySqlClient); Session.CharacterInfo.SynchronizeRespectData(MySqlClient); AchievementManager.ProgressUserAchievement(MySqlClient, TargetSession, "ACH_RespectEarned", 1); AchievementManager.ProgressUserAchievement(MySqlClient, Session, "ACH_RespectGiven", 1); } QuestManager.ProgressUserQuest(Session, QuestType.SOCIAL_RESPECT); }
private static void UserChangeRotation(Session Session, ClientMessage Message) { RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null) { return; } RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId); if (Actor == null || Actor.IsMoving) { return; } Vector2 PositionToFace = new Vector2(Message.PopWiredInt32(), Message.PopWiredInt32()); if ((Actor.Position.X == PositionToFace.X && Actor.Position.Y == PositionToFace.Y) || Actor.UserStatusses.ContainsKey("lay") || Actor.UserStatusses.ContainsKey("sit")) { return; } int NewRotation = 0; NewRotation = Rotation.Calculate(Actor.Position.GetVector2(), PositionToFace); if (Actor.BodyRotation != NewRotation) { Actor.BodyRotation = NewRotation; Actor.UpdateNeeded = true; } if (Actor.HeadRotation != NewRotation) { Actor.HeadRotation = NewRotation; Actor.UpdateNeeded = true; } }
private static void RespectPet(Session Session, ClientMessage Message) { if (Session.CharacterInfo.RespectCreditPets <= 0) { return; } RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance == null) { return; } RoomActor Actor = Instance.GetActorByReferenceId(Message.PopWiredUInt32(), RoomActorType.AiBot); if (Actor == null) { return; } Pet PetData = ((Bot)Actor.ReferenceObject).PetData; if (PetData == null) { return; } Session.CharacterInfo.RespectCreditPets = 500;/*--;*/ PetData.Score++; using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { Session.CharacterInfo.SynchronizeRespectData(MySqlClient); PetData.SynchronizeDatabase(MySqlClient); } Instance.BroadcastMessage(RoomPetUpdateComposer.Compose(Actor.ReferenceId, PetData)); }
public bool AddBotToRoom(Bot Bot) { uint ActorId = GenerateActorId(); RoomActor BotActor = RoomActor.TryCreateActor(ActorId, RoomActorType.AiBot, Bot.Id, Bot, new Vector3(Bot.InitialPosition.X, Bot.InitialPosition.Y, Bot.InitialPosition.Z), 2, this); Bot.Brain.Initialize(Bot); if (BotActor != null) { AddActorToRoom(BotActor); if (Bot.IsPet) { mPetCount++; } return(true); } return(false); }
public override void OnSelfEnterRoom(RoomInstance Instance) { mSelfActor = Instance.GetActorByReferenceId(mSelfBot.Id, RoomActorType.AiBot); if (mSelfActor == null) { return; } mNeedsRotation = false; mNextSpeechAttempt = RandomGenerator.GetNext(20, 255); mNextMovementAttempt = RandomGenerator.GetNext(20, 255); mServingItemId = 0; mServingActorId = 0; mMovingToServePos = false; mActorServePos = null; if (mSelfBot.Rotation >= 0) { mSelfActor.BodyRotation = mSelfBot.Rotation; mSelfActor.HeadRotation = mSelfBot.Rotation; } }
public bool TakeUserRights(uint UserId) { lock (mActorSyncRoot) { if (!mUsersWithRights.Contains(UserId)) { return(false); } mUsersWithRights.Remove(UserId); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { MySqlClient.SetParameter("roomid", RoomId); MySqlClient.SetParameter("userid", UserId); MySqlClient.ExecuteNonQuery("DELETE FROM room_rights WHERE room_id = @roomid AND user_id = @userid LIMIT 1"); } RoomActor Actor = GetActorByReferenceId(UserId); if (Actor != null) { Actor.RemoveStatus("flatctrl"); Actor.UpdateNeeded = true; Session ActorSession = SessionManager.GetSessionByCharacterId(Actor.ReferenceId); if (ActorSession != null) { ActorSession.SendData(RoomRightsRemovedComposer.Compose()); } } } return(true); }
public void BroadcastChatMessage(RoomActor Actor, string MessageText, bool Shout, int EmotionId) { lock (mActorSyncRoot) { foreach (RoomActor _Actor in mActors.Values) { ServerMessage Message = RoomChatComposer.Compose(Actor.Id, MessageText, EmotionId, Shout ? ChatType.Shout : ChatType.Say); if (_Actor.Type == RoomActorType.UserCharacter) { Session ActorSession = SessionManager.GetSessionByCharacterId(_Actor.ReferenceId); if (ActorSession == null || (Actor.Type == RoomActorType.UserCharacter && ActorSession.IgnoreCache.UserIsIgnored(Actor.ReferenceId))) { continue; } ActorSession.SendData(Message); } } foreach (RoomActor _Actor in mActors.Values) { if (_Actor.Type == RoomActorType.AiBot) { if (Actor.Id == _Actor.Id) { continue; } ((Bot)_Actor.ReferenceObject).Brain.OnUserChat(this, Actor, MessageText, Shout); } } } }
public bool GiveUserRights(uint UserId) { lock (mActorSyncRoot) { if (mUsersWithRights.Contains(UserId)) { return(false); } mUsersWithRights.Add(UserId); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { MySqlClient.SetParameter("roomid", RoomId); MySqlClient.SetParameter("userid", UserId); MySqlClient.ExecuteNonQuery("INSERT INTO room_rights (room_id,user_id) VALUES (@roomid,@userid)"); } RoomActor Actor = GetActorByReferenceId(UserId); if (Actor != null) { Actor.SetStatus("flatctrl"); Actor.UpdateNeeded = true; Session ActorSession = SessionManager.GetSessionByCharacterId(Actor.ReferenceId); if (ActorSession != null) { ActorSession.SendData(RoomRightsComposer.Compose()); } } } return(true); }
public override void OnUserEnter(RoomInstance Instance, RoomActor Actor) { if (mSelfActor == null || Actor.Type == RoomActorType.AiBot) { return; } if (mSelfBot.Effect > 0) { mSelfActor.ApplyEffect(mSelfBot.Effect); } }
public override void OnUserLeave(RoomInstance Instance, RoomActor Actor) { if (mSelfActor == null || Actor.Type == RoomActorType.AiBot) { return; } }
public bool AddUserToRoom(Session Session) { if (Session.AbsoluteRoomId != RoomId || !Session.Authenticated) { return(false); } uint ActorId = GenerateActorId(); if (ActorId == 0) { return(false); } Vector3 StartPosition = new Vector3(Model.DoorPosition.X, Model.DoorPosition.Y, Model.DoorPosition.Z); int StartRotation = Model.DoorRotation; RoomActor NewActor = RoomActor.TryCreateActor(ActorId, RoomActorType.UserCharacter, Session.CharacterId, Session.CharacterInfo, StartPosition, StartRotation, this); Item TargetTeleporter = null; if (Session.IsTeleporting) { TargetTeleporter = GetItem(Session.TargetTeleporterId); if (TargetTeleporter != null && !TargetTeleporter.TemporaryInteractionReferenceIds.ContainsKey(2)) { NewActor.Position = new Vector3(TargetTeleporter.RoomPosition.X, TargetTeleporter.RoomPosition.Y, TargetTeleporter.RoomPosition.Z); NewActor.HeadRotation = TargetTeleporter.RoomRotation; NewActor.BodyRotation = TargetTeleporter.RoomRotation; NewActor.UpdateNeeded = true; TargetTeleporter.TemporaryInteractionReferenceIds.Add(2, NewActor.Id); TargetTeleporter.DisplayFlags = "2"; TargetTeleporter.RequestUpdate(3); } Session.TargetTeleporterId = 0; Session.IsTeleporting = false; } if (NewActor == null) { return(false); } AddActorToRoom(NewActor); if (TargetTeleporter != null) { TargetTeleporter.BroadcastStateUpdate(this); } if (CheckUserRights(Session, true)) { NewActor.SetStatus("flatctrl", "useradmin"); Session.SendData(RoomOwnerRightsComposer.Compose()); Session.SendData(RoomRightsComposer.Compose()); } else if (CheckUserRights(Session)) { NewActor.SetStatus("flatctrl"); Session.SendData(RoomRightsComposer.Compose()); } if (Session.CurrentEffect > 0) { NewActor.ApplyEffect(Session.CurrentEffect); } WiredManager.HandleEnterRoom(NewActor); NewActor.UpdateNeeded = true; return(true); }
public void UpdateActorStatus(RoomActor Actor) { Vector2 Redirection = mRedirectGrid[Actor.Position.X, Actor.Position.Y]; if (Redirection != null) { Actor.Position = new Vector3(Redirection.X, Redirection.Y, GetUserStepHeight(Redirection)); } RoomTileEffect Effect = mTileEffects[Actor.Position.X, Actor.Position.Y]; if (Effect == null) { return; } Dictionary <string, string> CurrentStatusses = Actor.UserStatusses; if (Effect.Type == RoomTileEffectType.Sit && !CurrentStatusses.ContainsKey("mv")) { string OldStatus = (CurrentStatusses.ContainsKey("sit") ? CurrentStatusses["sit"] : string.Empty); string NewStatus = Math.Round(Effect.InteractionHeight, 1).ToString().Replace(',', '.'); if (Actor.BodyRotation != Effect.Rotation) { Actor.BodyRotation = Effect.Rotation; Actor.HeadRotation = Effect.Rotation; Actor.UpdateNeeded = true; } if (NewStatus != OldStatus) { Actor.SetStatus("sit", NewStatus); Actor.UpdateNeeded = true; } } else if (CurrentStatusses.ContainsKey("sit")) { Actor.RemoveStatus("sit"); Actor.UpdateNeeded = true; } if (Effect.Type == RoomTileEffectType.Lay && !CurrentStatusses.ContainsKey("mv")) { string OldStatus = (CurrentStatusses.ContainsKey("lay") ? CurrentStatusses["lay"] : string.Empty); string NewStatus = Math.Round(Effect.InteractionHeight, 1).ToString().Replace(',', '.'); if (Actor.BodyRotation != Effect.Rotation) { Actor.BodyRotation = Effect.Rotation; Actor.HeadRotation = Effect.Rotation; Actor.UpdateNeeded = true; } if (OldStatus != NewStatus) { Actor.SetStatus("lay", NewStatus); Actor.UpdateNeeded = true; } } else if (CurrentStatusses.ContainsKey("lay")) { Actor.RemoveStatus("lay"); Actor.UpdateNeeded = true; } if (Effect.Type == RoomTileEffectType.Effect) { if ((Actor.AvatarEffectId != Effect.EffectId || !Actor.AvatarEffectByItem)) { Actor.ApplyEffect(Effect.EffectId, true, true); } } else if (Actor.AvatarEffectByItem) { int ClearEffect = 0; if (Actor.Type == RoomActorType.UserCharacter) { Session SessionObject = SessionManager.GetSessionByCharacterId(Actor.ReferenceId); if (SessionObject != null) { ClearEffect = SessionObject.CurrentEffect; } } else { Bot BotObject = (Bot)Actor.ReferenceObject; if (BotObject != null) { ClearEffect = BotObject.Effect; } } Actor.ApplyEffect(ClearEffect, true, true); } if (Actor.Type == RoomActorType.UserCharacter && Effect.QuestData > 0) { Session SessionObject = SessionManager.GetSessionByCharacterId(Actor.ReferenceId); if (SessionObject != null) { QuestManager.ProgressUserQuest(SessionObject, QuestType.EXPLORE_FIND_ITEM, Effect.QuestData); } } }
public void HandleEnterRoom(RoomActor Actor) { foreach (WiredData data in mWired.Values) { Item Item = mInstance.GetItem (data.ItemId); if (Item.Definition.Behavior == ItemBehavior.WiredTrigger && WiredTypesUtil.TriggerFromInt (Item.Definition.BehaviorData) == WiredTriggerTypes.enter_room) { if (data.Data1 != "" && data.Data1 != Actor.Name) { continue; } Item.DisplayFlags = "1"; Item.BroadcastStateUpdate (mInstance); Item.DisplayFlags = ""; Item.RequestUpdate (4); ExecuteActions (Item, Actor); } } }
public bool HandleChat(String Message, RoomActor Actor) { Boolean doneAction = false; foreach (WiredData data in mWired.Values) { Item Item = mInstance.GetItem (data.ItemId); if (Item.Definition.Behavior == ItemBehavior.WiredTrigger && WiredTypesUtil.TriggerFromInt (Item.Definition.BehaviorData) == WiredTriggerTypes.says_something && data.Data1 == Message && (data.Data2 == 0 || data.Data2 == Actor.Id) ) { Item.DisplayFlags = "1"; Item.BroadcastStateUpdate (mInstance); Item.DisplayFlags = "2"; Item.RequestUpdate (4); ExecuteActions (Item, Actor); doneAction = true; } } return doneAction; }
public abstract void OnUserEnter(RoomInstance Instance, RoomActor Actor);
public void ExecuteActions(Item Item, RoomActor Actor) { Random rnd = new Random (); foreach (Item ActionItem in mInstance.GetItemsOnPosition(Item.RoomPosition.GetVector2())) { if (ActionItem.Definition.Behavior == ItemBehavior.WiredEffect) { ActionItem.DisplayFlags = "1"; ActionItem.BroadcastStateUpdate (mInstance); ActionItem.DisplayFlags = "2"; ActionItem.RequestUpdate (4); switch (WiredTypesUtil.EffectFromInt (ActionItem.Definition.BehaviorData)) { #region show_message case WiredEffectTypes.show_message: if (Actor == null) { continue; } Actor.Whisper (mWired [ActionItem.Id].Data1, 0, true); break; #endregion #region move_rotate case WiredEffectTypes.move_rotate: if (ActionItem.WiredData.Data2 == 0 && ActionItem.WiredData.Data3 == 0) { continue; } String[] ItemsToMove = ActionItem.WiredData.Data1.Split ('|'); foreach (String toMove in ItemsToMove) { uint ItemId; uint.TryParse (toMove, out ItemId); Item Move = mInstance.GetItem (ItemId); if (Move == null) { continue; } Vector2 NewPosition = new Vector2 (Move.RoomPosition.X, Move.RoomPosition.Y); switch (ActionItem.WiredData.Data2) { case 1: switch (rnd.Next (1, 5)) { case 1: NewPosition = new Vector2 (Move.RoomPosition.X - 1, Move.RoomPosition.Y); break; case 2: NewPosition = new Vector2 (Move.RoomPosition.X + 1, Move.RoomPosition.Y); break; case 3: NewPosition = new Vector2 (Move.RoomPosition.X, Move.RoomPosition.Y + 1); break; case 4: NewPosition = new Vector2 (Move.RoomPosition.X, Move.RoomPosition.Y - 1); break; } break; case 2: if (rnd.Next (0, 2) == 1) { NewPosition = new Vector2 (Move.RoomPosition.X - 1, Move.RoomPosition.Y); } else { NewPosition = new Vector2 (Move.RoomPosition.X + 1, Move.RoomPosition.Y); } break; case 3: if (rnd.Next (0, 2) == 1) { NewPosition = new Vector2 (Move.RoomPosition.X, Move.RoomPosition.Y - 1); } else { NewPosition = new Vector2 (Move.RoomPosition.X, Move.RoomPosition.Y + 1); } break; case 4: NewPosition = new Vector2 (Move.RoomPosition.X, Move.RoomPosition.Y - 1); break; case 5: NewPosition = new Vector2 (Move.RoomPosition.X + 1, Move.RoomPosition.Y); break; case 6: NewPosition = new Vector2 (Move.RoomPosition.X, Move.RoomPosition.Y + 1); break; case 7: NewPosition = new Vector2 (Move.RoomPosition.X - 1, Move.RoomPosition.Y); break; } int NewRotation = Move.RoomRotation; switch (ActionItem.WiredData.Data3) { case 1: NewRotation = NewRotation + 2; if (NewRotation == 8) { NewRotation = 0; } break; case 2: NewRotation = (NewRotation - 2); if (NewRotation == -2) { NewRotation = 6; } break; case 3: if (rnd.Next (0, 2) == 1) { goto case 1; } else { goto case 2; } } bool IsRotationOnly = (ActionItem.WiredData.Data2 == 0); Vector3 FinalizedPosition = mInstance.SetFloorItem (null, Move, NewPosition, NewRotation); if (FinalizedPosition != null) { Move.MoveToRoom (null, mInstance.RoomId, FinalizedPosition, NewRotation, ""); RoomManager.MarkWriteback (Move, false); mInstance.RegenerateRelativeHeightmap (); mInstance.BroadcastMessage (RoomItemUpdatedComposer.Compose (Move)); ItemEventDispatcher.InvokeItemEventHandler (null, Move, mInstance, ItemEventType.Moved, IsRotationOnly ? 1 : 0); } } break; #endregion #region match_to_sshot case WiredEffectTypes.match_to_sshot: String[] Selected = ActionItem.WiredData.Data5.Split ('+'); foreach (String FullData in Selected) { if (!FullData.Contains ('#')) { continue; } String[] Data = FullData.Split ('#'); if (Data.Length != 4) { continue; } uint Id = uint.Parse (Data [0]); String[] Position = Data [1].Split ('|'); int Rotation = int.Parse (Data [2]); String Flags = Data [3]; int X = int.Parse (Position [0]); int Y = int.Parse (Position [1]); uint Z = uint.Parse (Position [2]); Item AffectedItem = mInstance.GetItem (Id); if (AffectedItem == null) { continue; } Boolean IsRotationOnly = (X == AffectedItem.RoomPosition.X && Y == AffectedItem.RoomPosition.Y && Z == AffectedItem.RoomPosition.Z); Vector2 NewPosition = new Vector2 (X, Y); if (ActionItem.WiredData.Data2 == 1) { AffectedItem.Flags = Flags; AffectedItem.DisplayFlags = Item.Flags; AffectedItem.BroadcastStateUpdate (mInstance); } if (ActionItem.WiredData.Data3 == 0) { Rotation = AffectedItem.RoomRotation; } if (ActionItem.WiredData.Data4 == 0) { NewPosition = AffectedItem.RoomPosition.GetVector2 (); } if (ActionItem.WiredData.Data4 == 1 || ActionItem.WiredData.Data3 == 1) { Vector3 FinalizedPosition = mInstance.SetFloorItem (null, AffectedItem, NewPosition, Rotation); AffectedItem.MoveToRoom (null, mInstance.RoomId, FinalizedPosition, Rotation, ""); RoomManager.MarkWriteback (AffectedItem, false); mInstance.RegenerateRelativeHeightmap (); mInstance.BroadcastMessage (RoomItemUpdatedComposer.Compose (AffectedItem)); ItemEventDispatcher.InvokeItemEventHandler (null, AffectedItem, mInstance, ItemEventType.Moved, IsRotationOnly ? 1 : 0); } else if (ActionItem.WiredData.Data2 == 1) { RoomManager.MarkWriteback (AffectedItem, true); } } break; #endregion case WiredEffectTypes.teleport_to: if (Actor == null) { continue; } String[] Selected2 = ActionItem.WiredData.Data1.Split ('|'); String ItemIdS = Actor.FurniOnId.ToString (); while (Actor.FurniOnId.ToString() == ItemIdS) { ItemIdS = Selected2 [rnd.Next (0, Selected2.Length)]; } uint ItemId2; uint.TryParse (ItemIdS, out ItemId2); Item AffectedItem2 = mInstance.GetItem (ItemId2); if (AffectedItem2 == null) { continue; } Actor.PositionToSet = AffectedItem2.RoomPosition.GetVector2 (); Actor.UpdateNeeded = true; break; case WiredEffectTypes.toggle_state: String[] Selected3 = ActionItem.WiredData.Data1.Split ('|'); foreach (String ItemIdS2 in Selected3) { uint ItemId3; uint.TryParse (ItemIdS2, out ItemId3); Item AffectedItem3 = mInstance.GetItem (ItemId3); if (AffectedItem3 == null) { continue; } int CurrentState = 0; int.TryParse (AffectedItem3.Flags, out CurrentState); int NewState = CurrentState + 1; if (CurrentState < 0 || CurrentState >= (AffectedItem3.Definition.BehaviorData - 1)) { NewState = 0; } if (CurrentState != NewState) { AffectedItem3.Flags = NewState.ToString (); AffectedItem3.DisplayFlags = AffectedItem3.Flags; RoomManager.MarkWriteback (AffectedItem3, true); AffectedItem3.BroadcastStateUpdate (mInstance); } } break; } } } }
private bool AddActorToRoom(RoomActor Actor) { lock (mActorSyncRoot) { if (mActors.ContainsKey(Actor.Id)) { return false; } mActors.Add(Actor.Id, Actor); BroadcastMessage(RoomUserObjectListComposer.Compose(new List<RoomActor>() { Actor })); MarkActorCountSyncNeeded(); foreach (RoomActor _Actor in mActors.Values) { if (_Actor.Type == RoomActorType.AiBot) { if (_Actor.Id == Actor.Id) { ((Bot)_Actor.ReferenceObject).Brain.OnSelfEnterRoom(this); } else { ((Bot)_Actor.ReferenceObject).Brain.OnUserEnter(this, Actor); } } } return true; } }
/// <summary> /// Removes an actor from the room instance. DO NOT CALL DIRECTLY FOR HUMAN CHARACTERS. /// </summary> /// <param name="ActorId">Id of the actor to remove.</param> /// <returns>Boolean based on success of removal.</returns> public bool RemoveActorFromRoom(uint ActorId) { bool Success = false; lock (mActorSyncRoot) { RoomActor Actor = GetActor(ActorId); if (Actor == null) { return(false); } if (Actor.Type == RoomActorType.UserCharacter) { if (Actor.ReferenceId == Info.OwnerId && HasOngoingEvent) { StopEvent(); } Trade Trade = TradeManager.GetTradeForUser(Actor.ReferenceId); if (Trade != null) { TradeManager.StopTradeForUser(Trade.UserOne); TradeManager.StopTradeForUser(Trade.UserTwo); Session TargetSession = SessionManager.GetSessionByCharacterId(Actor.ReferenceId == Trade.UserOne ? Trade.UserTwo : Trade.UserOne); if (TargetSession != null) { TargetSession.SendData(TradeAbortedComposer.Compose(Actor.ReferenceId)); RoomActor TargetActor = GetActorByReferenceId(TargetSession.CharacterId); if (TargetActor != null) { TargetActor.RemoveStatus("trd"); TargetActor.UpdateNeeded = true; } } } } foreach (RoomActor _Actor in mActors.Values) { if (_Actor.Type == RoomActorType.AiBot) { if (_Actor.Id == Actor.Id) { Bot SelfBot = ((Bot)_Actor.ReferenceObject); SelfBot.Brain.OnSelfLeaveRoom(this); if (SelfBot.IsPet) { mPetCount--; } } else { ((Bot)_Actor.ReferenceObject).Brain.OnUserLeave(this, Actor); } } } Success = mActors.Remove(ActorId); if (Success) { BroadcastMessage(RoomUserRemovedComposer.Compose(ActorId)); MarkActorCountSyncNeeded(); } } return(Success); }
public abstract void OnUserChat(RoomInstance Instance, RoomActor Actor, string MessageText, bool Shout);
public void UpdateActorStatus(RoomActor Actor) { Vector2 Redirection = mRedirectGrid[Actor.Position.X, Actor.Position.Y]; if (Redirection != null) { Actor.Position = new Vector3(Redirection.X, Redirection.Y, GetUserStepHeight(Redirection)); } RoomTileEffect Effect = mTileEffects[Actor.Position.X, Actor.Position.Y]; if (Effect == null) { return; } Dictionary<string, string> CurrentStatusses = Actor.UserStatusses; if (Effect.Type == RoomTileEffectType.Sit && !CurrentStatusses.ContainsKey("mv")) { string OldStatus = (CurrentStatusses.ContainsKey("sit") ? CurrentStatusses["sit"] : string.Empty); string NewStatus = Math.Round(Effect.InteractionHeight, 1).ToString().Replace(',', '.'); if (Actor.BodyRotation != Effect.Rotation) { Actor.BodyRotation = Effect.Rotation; Actor.HeadRotation = Effect.Rotation; Actor.UpdateNeeded = true; } if (NewStatus != OldStatus) { Actor.SetStatus("sit", NewStatus); Actor.UpdateNeeded = true; } } else if (CurrentStatusses.ContainsKey("sit")) { Actor.RemoveStatus("sit"); Actor.UpdateNeeded = true; } if (Effect.Type == RoomTileEffectType.Lay && !CurrentStatusses.ContainsKey("mv")) { string OldStatus = (CurrentStatusses.ContainsKey("lay") ? CurrentStatusses["lay"] : string.Empty); string NewStatus = Math.Round(Effect.InteractionHeight, 1).ToString().Replace(',', '.'); if (Actor.BodyRotation != Effect.Rotation) { Actor.BodyRotation = Effect.Rotation; Actor.HeadRotation = Effect.Rotation; Actor.UpdateNeeded = true; } if (OldStatus != NewStatus) { Actor.SetStatus("lay", NewStatus); Actor.UpdateNeeded = true; } } else if (CurrentStatusses.ContainsKey("lay")) { Actor.RemoveStatus("lay"); Actor.UpdateNeeded = true; } if (Effect.Type == RoomTileEffectType.Effect) { if ((Actor.AvatarEffectId != Effect.EffectId || !Actor.AvatarEffectByItem)) { Actor.ApplyEffect(Effect.EffectId, true, true); } } else if (Actor.AvatarEffectByItem) { int ClearEffect = 0; if (Actor.Type == RoomActorType.UserCharacter) { Session SessionObject = SessionManager.GetSessionByCharacterId(Actor.ReferenceId); if (SessionObject != null) { ClearEffect = SessionObject.CurrentEffect; } } else { Bot BotObject = (Bot)Actor.ReferenceObject; if (BotObject != null) { ClearEffect = BotObject.Effect; } } Actor.ApplyEffect(ClearEffect, true, true); } if (Actor.Type == RoomActorType.UserCharacter && Effect.QuestData > 0) { Session SessionObject = SessionManager.GetSessionByCharacterId(Actor.ReferenceId); if (SessionObject != null) { QuestManager.ProgressUserQuest(SessionObject, QuestType.EXPLORE_FIND_ITEM, Effect.QuestData); } } }
public abstract void OnUserLeave(RoomInstance Instance, RoomActor Actor);