public VMAvatar GetAvatarByPersist(uint id) { VMAvatar result = null; Context.ObjectQueries.AvatarsByPersist.TryGetValue(id, out result); return(result); }
public UIPersonIcon(VMAvatar ava, VM vm, bool small) { Avatar = ava; this.vm = vm; Small = small; UpdateAvatarState(((VMTSOAvatarState)Avatar.TSOState).Permissions); OnButtonClick += CenterPerson; }
private void HandleTimePropsEvent(TimePropertyListItem tp) { VMAvatar avatar = this; var evt = tp.Properties["xevt"]; if (evt != null) { var eventValue = short.Parse(evt); avatar.CurrentAnimationState.EventQueue.Add(eventValue); avatar.CurrentAnimationState.EventsRun++; } var rhevt = tp.Properties["righthand"]; if (rhevt != null) { var eventValue = short.Parse(rhevt); avatar.Avatar.RightHandGesture = (SimHandGesture)eventValue; } var lhevt = tp.Properties["lefthand"]; if (lhevt != null) { var eventValue = short.Parse(lhevt); avatar.Avatar.LeftHandGesture = (SimHandGesture)eventValue; } var soundevt = tp.Properties["sound"]; var owner = this; if (UseWorld && soundevt != null && owner.SoundThreads.FirstOrDefault(x => x.Name == soundevt) == null) { var thread = TSO.HIT.HITVM.Get().PlaySoundEvent(soundevt); if (thread != null) { if (thread is HITThread) { SubmitHITVars((HITThread)thread); } if (!thread.AlreadyOwns(owner.ObjectID)) { thread.AddOwner(owner.ObjectID); } var entry = new VMSoundEntry() { Sound = thread, Pan = true, Zoom = true, }; owner.SoundThreads.Add(entry); owner.TickSounds(); } } }
public void Load(VMMarshal input) { var clientJoin = (Context.Architecture == null); var oldWorld = Context.World; Context = new VMContext(input.Context, Context); Context.Globals = FSO.Content.Content.Get().WorldObjectGlobals.Get("global"); Context.VM = this; Context.Architecture.RegenRoomMap(); Context.RegeneratePortalInfo(); var oldSounds = new List <VMSoundTransfer>(); if (Entities != null) //free any object resources here. { foreach (var obj in Entities) { obj.Dead = true; if (obj.HeadlineRenderer != null) { obj.HeadlineRenderer.Dispose(); } oldSounds.AddRange(obj.GetActiveSounds()); } } Entities = new List <VMEntity>(); ObjectsById = new Dictionary <short, VMEntity>(); foreach (var ent in input.Entities) { VMEntity realEnt; var objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID); if (ent is VMAvatarMarshal) { var avatar = new VMAvatar(objDefinition); avatar.Load((VMAvatarMarshal)ent); if (UseWorld) { Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI); } realEnt = avatar; } else { var worldObject = new ObjectComponent(objDefinition); var obj = new VMGameObject(objDefinition, worldObject); obj.Load((VMGameObjectMarshal)ent); Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI); Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position); obj.Position = obj.Position; realEnt = obj; } realEnt.GenerateTreeByName(Context); Entities.Add(realEnt); Context.SetToNextCache.NewObject(realEnt); ObjectsById.Add(ent.ObjectID, realEnt); } int i = 0; foreach (var ent in input.Entities) { var threadMarsh = input.Threads[i]; var realEnt = Entities[i++]; realEnt.Thread = new VMThread(threadMarsh, Context, realEnt); if (realEnt is VMAvatar) { ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context); } else { ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context); } } foreach (var multi in input.MultitileGroups) { new VMMultitileGroup(multi, Context); //should self register } foreach (var ent in Entities) { if (ent.Container == null) { ent.PositionChange(Context, true); //called recursively for contained objects. } } GlobalState = input.GlobalState; PlatformState = input.PlatformState; ObjectId = input.ObjectId; //just a few final changes to refresh everything, and avoid signalling objects var clock = Context.Clock; Context.Architecture.SetTimeOfDay(clock.Hours / 24.0 + clock.Minutes / (24.0 * 60) + clock.Seconds / (24.0 * 60 * 60)); Context.Architecture.RegenRoomMap(); Context.RegeneratePortalInfo(); Context.Architecture.WallDirtyState(input.Context.Architecture); foreach (var snd in oldSounds) { //find new owners var obj = GetObjectById(snd.SourceID); if (obj == null || obj.Object.GUID != snd.SourceGUID) { snd.SFX.Sound.RemoveOwner(snd.SourceID); } else { obj.SoundThreads.Add(snd.SFX); // successfully transfer sound to new object } } if (clientJoin) { //run clientJoin functions to play object sounds, update some gfx. foreach (var obj in Entities) { obj.ExecuteEntryPoint(30, Context, true); } } if (OnFullRefresh != null) { OnFullRefresh(); } }
public override void Tick() { Velocity = new Vector3(0, 0, 0); base.Tick(); if (Message != "") { if (MessageTimeout-- > 0) { if (MessageTimeout == 0) { SetPersonData(VMPersonDataVariable.ChatBaloonOn, 0); m_Message = ""; } } } if (Thread != null && Thread.ThreadBreak == Engine.VMThreadBreakMode.Pause) { return; } if (PersonData[(int)VMPersonDataVariable.OnlineJobStatusFlags] == 0) { PersonData[(int)VMPersonDataVariable.OnlineJobStatusFlags] = 1; } if (Thread != null) { MotiveDecay.Tick(this, Thread.Context); SetPersonData(VMPersonDataVariable.OnlineJobGrade, Math.Max((short)0, Thread.Context.VM.GetGlobalValue(11))); //force job grade to what we expect if (Position == LotTilePos.OUT_OF_WORLD) { //uh oh! var mailbox = Thread.Context.VM.Entities.FirstOrDefault(x => (x.Object.OBJ.GUID == 0xEF121974 || x.Object.OBJ.GUID == 0x1D95C9B0)); if (mailbox != null) { VMFindLocationFor.FindLocationFor(this, mailbox, Thread.Context); } } } //animation update for avatars VMAvatar avatar = this; float totalWeight = 0f; foreach (var state in Animations) { totalWeight += state.Weight; if (!state.EndReached && state.Weight != 0) { if (state.PlayingBackwards) { state.CurrentFrame -= state.Speed; } else { state.CurrentFrame += state.Speed; } var currentFrame = state.CurrentFrame; var currentTime = currentFrame * 33.33f; var timeProps = state.TimePropertyLists; if (!state.PlayingBackwards) { for (var i = 0; i < timeProps.Count; i++) { var tp = timeProps[i]; if (tp.ID > currentTime) { break; } timeProps.RemoveAt(0); i--; HandleTimePropsEvent(tp); } } else { for (var i = timeProps.Count - 1; i >= 0; i--) { var tp = timeProps[i]; if (tp.ID < currentTime) { break; } timeProps.RemoveAt(timeProps.Count - 1); HandleTimePropsEvent(tp); } } var status = Animator.RenderFrame(avatar.Avatar, state.Anim, (int)state.CurrentFrame, state.CurrentFrame % 1f, state.Weight / totalWeight); if (status != AnimationStatus.IN_PROGRESS) { if (state.Loop) { if (state.PlayingBackwards) { state.CurrentFrame += state.Anim.NumFrames; } else { state.CurrentFrame -= state.Anim.NumFrames; } } else { state.EndReached = true; } } } } if (avatar.CarryAnimationState != null) { var status = Animator.RenderFrame(avatar.Avatar, avatar.CarryAnimationState.Anim, (int)avatar.CarryAnimationState.CurrentFrame, 0.0f, 1f); //currently don't advance frames... I don't think any of them are animated anyways. } for (int i = 0; i < 16; i++) { MotiveChanges[i].Tick(this); //tick over motive changes } avatar.Avatar.ReloadSkeleton(); PersonData[(int)VMPersonDataVariable.TickCounter]++; if (KillTimeout > -1) { if (++KillTimeout > FORCE_DELETE_TIMEOUT) { Delete(true, Thread.Context); } else { SetPersonData(VMPersonDataVariable.RenderDisplayFlags, 1); SetValue(VMStackObjectVariable.Hidden, (short)((KillTimeout % 30) / 15)); if (Thread.BlockingState != null) { Thread.BlockingState.WaitTime = Math.Max(Thread.BlockingState.WaitTime, 1000000); //make most things time out } UserLeaveLot(); //keep forcing } } }
public VMMultitileGroup CreateObjectInstance(UInt32 GUID, LotTilePos pos, Direction direction, short MainStackOBJ, short MainParam, bool ghostImage) { VMMultitileGroup group = new VMMultitileGroup(); var objDefinition = FSO.Content.Content.Get().WorldObjects.Get(GUID); if (objDefinition == null) { return null; } var master = objDefinition.OBJ.MasterID; if (master != 0) { group.MultiTile = true; var objd = objDefinition.Resource.List<OBJD>(); for (int i = 0; i < objd.Count; i++) { if (objd[i].MasterID == master && objd[i].SubIndex != -1) //if sub-part of this object, make it! { var subObjDefinition = FSO.Content.Content.Get().WorldObjects.Get(objd[i].GUID); if (subObjDefinition != null) { var worldObject = new ObjectComponent(subObjDefinition); var vmObject = new VMGameObject(subObjDefinition, worldObject); vmObject.GhostImage = ghostImage; vmObject.MasterDefinition = objDefinition.OBJ; vmObject.UseTreeTableOf(objDefinition); vmObject.MainParam = MainParam; vmObject.MainStackOBJ = MainStackOBJ; group.Objects.Add(vmObject); vmObject.MultitileGroup = group; if (!ghostImage) VM.AddEntity(vmObject); } } } group.Init(this); VMPlacementError couldPlace = group.ChangePosition(pos, direction, this).Status; return group; } else { if (objDefinition.OBJ.ObjectType == OBJDType.Person) //person { var vmObject = new VMAvatar(objDefinition); vmObject.MultitileGroup = group; group.Objects.Add(vmObject); vmObject.GhostImage = ghostImage; if (!ghostImage) VM.AddEntity(vmObject); if (UseWorld) Blueprint.AddAvatar((AvatarComponent)vmObject.WorldUI); vmObject.MainParam = MainParam; vmObject.MainStackOBJ = MainStackOBJ; group.Init(this); vmObject.SetPosition(pos, direction, this); return group; } else { var worldObject = new ObjectComponent(objDefinition); var vmObject = new VMGameObject(objDefinition, worldObject); vmObject.MultitileGroup = group; group.Objects.Add(vmObject); vmObject.GhostImage = ghostImage; if (!ghostImage) VM.AddEntity(vmObject); vmObject.MainParam = MainParam; vmObject.MainStackOBJ = MainStackOBJ; group.Init(this); vmObject.SetPosition(pos, direction, this); return group; } } }
public void LoadAsync(VMMarshal input) { FSOVAsyncLoading = true; var lastBp = Context.Blueprint; //try keep this alive I suppose //var oldWorld = Context.World; //TS1 = input.TS1; Context = new VMContext(input.Context, Context); Context.VM = this; var idMap = input.Context.Architecture.IDMap; if (idMap != null) { idMap.Apply(this); } Context.Architecture.RegenRoomMap(); Context.RegeneratePortalInfo(); Context.Architecture.Terrain.RegenerateCenters(); if (VM.UseWorld) { Context.Blueprint.Altitude = Context.Architecture.Terrain.Heights; Context.Blueprint.AltitudeCenters = Context.Architecture.Terrain.Centers; } var oldSounds = new List <VMSoundTransfer>(); if (Entities != null) //free any object resources here. { foreach (var obj in Entities) { obj.Dead = true; if (obj.HeadlineRenderer != null) { if (UseWorld) { GameThread.InUpdate(() => { obj.HeadlineRenderer.Dispose(); }); } } oldSounds.AddRange(obj.GetActiveSounds()); } } SoundEntities = new HashSet <VMEntity>(); Entities = new List <VMEntity>(); Scheduler.Reset(); ObjectsById = new Dictionary <short, VMEntity>(); FSOVObjTotal = input.Entities.Length; foreach (var ent in input.Entities) { VMEntity realEnt; var objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID); if (objDefinition == null) { LoadErrors.Add(new VMLoadError(VMLoadErrorCode.MISSING_OBJECT, "0x" + ent.GUID.ToString("X8") + " " + input.MultitileGroups.FirstOrDefault(x => x.Objects.Contains(ent.ObjectID))?.Name ?? "(unknown name)", (ushort)ent.ObjectID)); ent.LoadFailed = true; continue; } if (ent is VMAvatarMarshal) { var avatar = new VMAvatar(objDefinition); avatar.Load((VMAvatarMarshal)ent); if (UseWorld) { Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI); } realEnt = avatar; } else { var worldObject = Context.MakeObjectComponent(objDefinition); var obj = new VMGameObject(objDefinition, worldObject); obj.Load((VMGameObjectMarshal)ent); if (UseWorld) { Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI); Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position); } obj.Position = obj.Position; realEnt = obj; } realEnt.FetchTreeByName(Context); Entities.Add(realEnt); Context.ObjectQueries.NewObject(realEnt); ObjectsById.Add(ent.ObjectID, realEnt); FSOVObjLoaded++; } int i = 0; int j = 0; foreach (var ent in input.Entities) { if (ent.LoadFailed) { i++; continue; } var threadMarsh = input.Threads[i]; var realEnt = Entities[j++]; i++; realEnt.Thread = new VMThread(threadMarsh, Context, realEnt); Scheduler.ScheduleTickIn(realEnt, 1); if (realEnt is VMAvatar) { ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context); } else { ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context); } } foreach (var multi in input.MultitileGroups) { var grp = new VMMultitileGroup(multi, Context); //should self register if (VM.UseWorld) { var b = grp.BaseObject; var avgPos = new LotTilePos(); foreach (var obj in grp.Objects) { avgPos += obj.Position; } avgPos /= Math.Max(grp.Objects.Count, 1); foreach (var obj in grp.Objects) { var off = obj.Position - avgPos; obj.WorldUI.MTOffset = new Vector3(off.x, off.y, 0); obj.Position = obj.Position; } } var persist = grp.BaseObject?.PersistID ?? 0; if (persist != 0 && grp.BaseObject is VMGameObject) { Context.ObjectQueries.RegisterMultitilePersist(grp, persist); } } foreach (var ent in Entities) { if (ent.Container == null) { ent.PositionChange(Context, true); //called recursively for contained objects. } } GlobalState = input.GlobalState; if (TS1) { ((VMTS1LotState)input.PlatformState).CurrentFamily = TS1State.CurrentFamily; } var lastPlatformState = PlatformState; PlatformState = input.PlatformState; PlatformState.ActivateValidator(this); if (lastPlatformState != null && lastPlatformState is VMTSOLotState) { TSOState.Names = ((VMTSOLotState)lastPlatformState).Names; } ObjectId = input.ObjectId; //just a few final changes to refresh everything, and avoid signalling objects var clock = Context.Clock; Context.Architecture.SetTimeOfDay(); Context.Architecture.SignalAllDirty(); Context.DisableRouteInvalidation = true; Context.Architecture.Tick(); Context.DisableRouteInvalidation = false; Context.Architecture.WallDirtyState(input.Context.Architecture); if (oldSounds.Count > 0) { GameThread.InUpdate(() => { foreach (var snd in oldSounds) { //find new owners var obj = GetObjectById(snd.SourceID); if (obj == null || obj.Object.GUID != snd.SourceGUID) { snd.SFX.Sound.RemoveOwner(snd.SourceID); } else { SoundEntities.Add(obj); obj.SoundThreads.Add(snd.SFX); // successfully transfer sound to new object } } }); } Context.UpdateTSOBuildableArea(); Tuning = input.Tuning; UpdateTuning(); if (OnFullRefresh != null) { OnFullRefresh(); } }
public override void Tick() { Velocity = new Vector3(0, 0, 0); base.Tick(); if (Message != "") { if (MessageTimeout-- > 0) { if (MessageTimeout == 0) { SetPersonData(VMPersonDataVariable.ChatBaloonOn, 0); m_Message = ""; } } } if (Thread != null && Thread.ThreadBreak == Engine.VMThreadBreakMode.Pause) { return; } if (PersonData[(int)VMPersonDataVariable.OnlineJobStatusFlags] == 0) { PersonData[(int)VMPersonDataVariable.OnlineJobStatusFlags] = 1; } if (Thread != null) { SetPersonData(VMPersonDataVariable.OnlineJobGrade, Math.Max((short)0, Thread.Context.VM.GetGlobalValue(11))); //force job grade to what we expect } //animation update for avatars VMAvatar avatar = this; if (avatar.Position == LotTilePos.OUT_OF_WORLD) { avatar.Position = new LotTilePos(8, 8, 1); } float totalWeight = 0f; foreach (var state in Animations) { totalWeight += state.Weight; if (!state.EndReached && state.Weight != 0) { if (state.PlayingBackwards) { state.CurrentFrame -= state.Speed; } else { state.CurrentFrame += state.Speed; } var currentFrame = state.CurrentFrame; var currentTime = currentFrame * 33.33f; var timeProps = state.TimePropertyLists; if (!state.PlayingBackwards) { for (var i = 0; i < timeProps.Count; i++) { var tp = timeProps[i]; if (tp.ID > currentTime) { break; } timeProps.RemoveAt(0); i--; HandleTimePropsEvent(tp); } } else { for (var i = timeProps.Count - 1; i >= 0; i--) { var tp = timeProps[i]; if (tp.ID < currentTime) { break; } timeProps.RemoveAt(timeProps.Count - 1); HandleTimePropsEvent(tp); } } var status = Animator.RenderFrame(avatar.Avatar, state.Anim, (int)state.CurrentFrame, state.CurrentFrame % 1f, state.Weight / totalWeight); if (status != AnimationStatus.IN_PROGRESS) { if (state.Loop) { if (state.PlayingBackwards) { state.CurrentFrame += state.Anim.NumFrames; } else { state.CurrentFrame -= state.Anim.NumFrames; } } else { state.EndReached = true; } } } } if (avatar.CarryAnimationState != null) { var status = Animator.RenderFrame(avatar.Avatar, avatar.CarryAnimationState.Anim, (int)avatar.CarryAnimationState.CurrentFrame, 0.0f, 1f); //currently don't advance frames... I don't think any of them are animated anyways. } for (int i = 0; i < 16; i++) { MotiveChanges[i].Tick(this); //tick over motive changes } avatar.Avatar.ReloadSkeleton(); PersonData[(int)VMPersonDataVariable.TickCounter]++; }
public void Load(VMMarshal input) { var clientJoin = (Context.Architecture == null); var oldWorld = Context.World; Context = new VMContext(input.Context, Context); Context.Globals = FSO.Content.Content.Get().WorldObjectGlobals.Get("global"); Context.VM = this; Context.Architecture.RegenRoomMap(); Context.RegeneratePortalInfo(); var oldSounds = new List<VMSoundTransfer>(); if (Entities != null) //free any object resources here. { foreach (var obj in Entities) { obj.Dead = true; if (obj.HeadlineRenderer != null) obj.HeadlineRenderer.Dispose(); oldSounds.AddRange(obj.GetActiveSounds()); } } Entities = new List<VMEntity>(); ObjectsById = new Dictionary<short, VMEntity>(); foreach (var ent in input.Entities) { VMEntity realEnt; var objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID); if (ent is VMAvatarMarshal) { var avatar = new VMAvatar(objDefinition); avatar.Load((VMAvatarMarshal)ent); if (UseWorld) Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI); realEnt = avatar; } else { var worldObject = new ObjectComponent(objDefinition); var obj = new VMGameObject(objDefinition, worldObject); obj.Load((VMGameObjectMarshal)ent); Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI); Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position); obj.Position = obj.Position; realEnt = obj; } realEnt.GenerateTreeByName(Context); Entities.Add(realEnt); Context.SetToNextCache.NewObject(realEnt); ObjectsById.Add(ent.ObjectID, realEnt); } int i = 0; foreach (var ent in input.Entities) { var threadMarsh = input.Threads[i]; var realEnt = Entities[i++]; realEnt.Thread = new VMThread(threadMarsh, Context, realEnt); if (realEnt is VMAvatar) ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context); else ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context); } foreach (var multi in input.MultitileGroups) { new VMMultitileGroup(multi, Context); //should self register } foreach (var ent in Entities) { if (ent.Container == null) ent.PositionChange(Context, true); //called recursively for contained objects. } GlobalState = input.GlobalState; PlatformState = input.PlatformState; ObjectId = input.ObjectId; //just a few final changes to refresh everything, and avoid signalling objects var clock = Context.Clock; Context.Architecture.SetTimeOfDay(clock.Hours / 24.0 + clock.Minutes / (24.0 * 60) + clock.Seconds / (24.0 * 60 * 60)); Context.Architecture.RegenRoomMap(); Context.RegeneratePortalInfo(); Context.Architecture.WallDirtyState(input.Context.Architecture); foreach (var snd in oldSounds) { //find new owners var obj = GetObjectById(snd.SourceID); if (obj == null || obj.Object.GUID != snd.SourceGUID) snd.SFX.Sound.RemoveOwner(snd.SourceID); else obj.SoundThreads.Add(snd.SFX); // successfully transfer sound to new object } if (clientJoin) { //run clientJoin functions to play object sounds, update some gfx. foreach (var obj in Entities) { obj.ExecuteEntryPoint(30, Context, true); } } if (OnFullRefresh != null) OnFullRefresh(); }
public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState state) { base.Update(state); if (SelectedAvatar != null) { if (SelectedAvatar != LastSelected) { if (Thumb != null) Remove(Thumb); Thumb = new UIPersonIcon(SelectedAvatar, LotController.vm, false); UpdateThumbPosition(); Add(Thumb); LastSelected = SelectedAvatar; } UpdateMotives(); } if (LastEODConfig != LotController.EODs.DisplayMode) { HideEOD = false; SetInEOD(LotController.EODs.DisplayMode, LotController.EODs.ActiveEOD); } if (LotController.EODs.EODMessage != (string)MsgWinTextEntry.Items[0].Data) { MsgWinTextEntry.Items[0].Data = LotController.EODs.EODMessage; MsgWinTextEntry.Items[0].Columns[0] = LotController.EODs.EODMessage; } if (LotController.EODs.EODTime != TimerTextEntry.CurrentText) TimerTextEntry.CurrentText = LotController.EODs.EODTime; }
public void Load(VMMarshal input) { var clientJoin = (Context.Architecture == null); //var oldWorld = Context.World; Context = new VMContext(input.Context, Context); Context.VM = this; Context.Architecture.RegenRoomMap(); Context.RegeneratePortalInfo(); Context.Architecture.Terrain.RegenerateCenters(); if (VM.UseWorld) { Context.Blueprint.Altitude = Context.Architecture.Terrain.Heights; Context.Blueprint.AltitudeCenters = Context.Architecture.Terrain.Centers; } var oldSounds = new List <VMSoundTransfer>(); if (Entities != null) //free any object resources here. { foreach (var obj in Entities) { obj.Dead = true; if (obj.HeadlineRenderer != null) { obj.HeadlineRenderer.Dispose(); } oldSounds.AddRange(obj.GetActiveSounds()); } } Entities = new List <VMEntity>(); Scheduler.Reset(); ObjectsById = new Dictionary <short, VMEntity>(); foreach (var ent in input.Entities) { VMEntity realEnt; var objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID); if (ent is VMAvatarMarshal) { var avatar = new VMAvatar(objDefinition); avatar.Load((VMAvatarMarshal)ent); if (UseWorld) { Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI); } realEnt = avatar; } else { var worldObject = Context.MakeObjectComponent(objDefinition); var obj = new VMGameObject(objDefinition, worldObject); obj.Load((VMGameObjectMarshal)ent); if (UseWorld) { Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI); Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position); } obj.Position = obj.Position; realEnt = obj; } realEnt.FetchTreeByName(Context); Entities.Add(realEnt); Context.ObjectQueries.NewObject(realEnt); ObjectsById.Add(ent.ObjectID, realEnt); } int i = 0; foreach (var ent in input.Entities) { var threadMarsh = input.Threads[i]; var realEnt = Entities[i++]; realEnt.Thread = new VMThread(threadMarsh, Context, realEnt); Scheduler.ScheduleTickIn(realEnt, 1); if (realEnt is VMAvatar) { ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context); } else { ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context); } } foreach (var multi in input.MultitileGroups) { var grp = new VMMultitileGroup(multi, Context); //should self register if (VM.UseWorld) { var b = grp.BaseObject; var avgPos = new LotTilePos(); foreach (var obj in grp.Objects) { avgPos += obj.Position; } avgPos /= grp.Objects.Count; foreach (var obj in grp.Objects) { var off = obj.Position - avgPos; obj.WorldUI.MTOffset = new Vector3(off.x, off.y, 0); obj.Position = obj.Position; } } var persist = grp.BaseObject?.PersistID ?? 0; if (persist != 0 && grp.BaseObject is VMGameObject) { Context.ObjectQueries.RegisterMultitilePersist(grp, persist); } } foreach (var ent in Entities) { if (ent.Container == null) { ent.PositionChange(Context, true); //called recursively for contained objects. } } GlobalState = input.GlobalState; PlatformState = input.PlatformState; ObjectId = input.ObjectId; //just a few final changes to refresh everything, and avoid signalling objects var clock = Context.Clock; Context.Architecture.SetTimeOfDay(clock.Hours / 24.0 + clock.Minutes / (24.0 * 60) + clock.Seconds / (24.0 * 60 * 60)); Context.Architecture.SignalAllDirty(); Context.DisableRouteInvalidation = true; Context.Architecture.Tick(); Context.DisableRouteInvalidation = false; Context.Architecture.WallDirtyState(input.Context.Architecture); foreach (var snd in oldSounds) { //find new owners var obj = GetObjectById(snd.SourceID); if (obj == null || obj.Object.GUID != snd.SourceGUID) { snd.SFX.Sound.RemoveOwner(snd.SourceID); } else { obj.SoundThreads.Add(snd.SFX); // successfully transfer sound to new object } } if (clientJoin) { //run clientJoin functions to play object sounds, update some gfx. foreach (var obj in Entities) { obj.ExecuteEntryPoint(30, Context, true); } } Context.UpdateTSOBuildableArea(); if (OnFullRefresh != null) { OnFullRefresh(); } }
private string GetAvatarString(VMAvatar ava) { int prefixNum = 3; if (ava.IsPet) prefixNum = 5; else if (ava.PersistID < 65536) prefixNum = 4; else { var permissionsLevel = ((VMTSOAvatarState)ava.TSOState).Permissions; switch (permissionsLevel) { case VMTSOAvatarPermissions.Visitor: prefixNum = 3; break; case VMTSOAvatarPermissions.Roommate: case VMTSOAvatarPermissions.BuildBuyRoommate: prefixNum = 2; break; case VMTSOAvatarPermissions.Admin: case VMTSOAvatarPermissions.Owner: prefixNum = 1; break; } } return GameFacade.Strings.GetString("217", prefixNum.ToString()) + ava.ToString(); }
public void Load(VMMarshal input) { var oldWorld = Context.World; Context = new VMContext(input.Context, oldWorld); Context.Globals = FSO.Content.Content.Get().WorldObjectGlobals.Get("global"); Context.VM = this; Context.Architecture.RegenRoomMap(); Context.RegeneratePortalInfo(); Entities = new List<VMEntity>(); ObjectsById = new Dictionary<short, VMEntity>(); foreach (var ent in input.Entities) { VMEntity realEnt; var objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID); if (ent is VMAvatarMarshal) { var avatar = new VMAvatar(objDefinition); avatar.Load((VMAvatarMarshal)ent); if (UseWorld) Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI); realEnt = avatar; } else { var worldObject = new ObjectComponent(objDefinition); var obj = new VMGameObject(objDefinition, worldObject); obj.Load((VMGameObjectMarshal)ent); obj.RefreshBlueprint(Context); obj.Position = obj.Position; realEnt = obj; } realEnt.GenerateTreeByName(Context); Entities.Add(realEnt); ObjectsById.Add(ent.ObjectID, realEnt); } int i = 0; foreach (var ent in input.Entities) { var threadMarsh = input.Threads[i]; var realEnt = Entities[i++]; realEnt.Thread = new VMThread(threadMarsh, Context, realEnt); if (realEnt is VMAvatar) ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context); else ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context); } foreach (var multi in input.MultitileGroups) { new VMMultitileGroup(multi, Context); //should self register } foreach (var ent in Entities) ent.PositionChange(Context, true); GlobalState = input.GlobalState; ObjectId = input.ObjectId; //just a few final changes to refresh everything, and avoid signalling objects Context.Architecture.RegenRoomMap(); Context.RegeneratePortalInfo(); Context.Architecture.WallDirtyState(input.Context.Architecture); if (OnFullRefresh != null) OnFullRefresh(); }
public VMMultitileGroup CreateObjectInstance(UInt32 GUID, LotTilePos pos, Direction direction, short MainStackOBJ, short MainParam, bool ghostImage) { VMMultitileGroup group = new VMMultitileGroup(); var objDefinition = FSO.Content.Content.Get().WorldObjects.Get(GUID); if (objDefinition == null) { return(null); } var master = objDefinition.OBJ.MasterID; if (master != 0 && objDefinition.OBJ.SubIndex == -1) { group.MultiTile = true; var objd = objDefinition.Resource.List <OBJD>(); for (int i = 0; i < objd.Count; i++) { if (objd[i].MasterID == master && objd[i].SubIndex != -1) //if sub-part of this object, make it! { var subObjDefinition = FSO.Content.Content.Get().WorldObjects.Get(objd[i].GUID); if (subObjDefinition != null) { var worldObject = new ObjectComponent(subObjDefinition); var vmObject = new VMGameObject(subObjDefinition, worldObject); vmObject.GhostImage = ghostImage; if (UseWorld) { Blueprint.AddObject(worldObject); } vmObject.MasterDefinition = objDefinition.OBJ; vmObject.UseTreeTableOf(objDefinition); vmObject.MainParam = MainParam; vmObject.MainStackOBJ = MainStackOBJ; group.AddObject(vmObject); vmObject.MultitileGroup = group; if (!ghostImage) { VM.AddEntity(vmObject); } } } } group.Init(this); VMPlacementError couldPlace = group.ChangePosition(pos, direction, this).Status; return(group); } else { if (objDefinition.OBJ.ObjectType == OBJDType.Person) //person { var vmObject = new VMAvatar(objDefinition); vmObject.MultitileGroup = group; group.AddObject(vmObject); vmObject.GhostImage = ghostImage; if (!ghostImage) { VM.AddEntity(vmObject); } if (UseWorld) { Blueprint.AddAvatar((AvatarComponent)vmObject.WorldUI); } vmObject.MainParam = MainParam; vmObject.MainStackOBJ = MainStackOBJ; group.Init(this); vmObject.SetPosition(pos, direction, this); return(group); } else { var worldObject = new ObjectComponent(objDefinition); var vmObject = new VMGameObject(objDefinition, worldObject); vmObject.MultitileGroup = group; group.AddObject(vmObject); vmObject.GhostImage = ghostImage; if (!ghostImage) { VM.AddEntity(vmObject); } if (UseWorld && Blueprint != null) { Blueprint.AddObject(worldObject); } vmObject.MainParam = MainParam; vmObject.MainStackOBJ = MainStackOBJ; group.Init(this); vmObject.SetPosition(pos, direction, this); return(group); } } }
public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState state) { base.Update(state); if (SelectedAvatar != null) { if (SelectedAvatar != LastSelected) { Thumbnail.Texture = SelectedAvatar.GetIcon(GameFacade.GraphicsDevice); Thumbnail.Tooltip = SelectedAvatar.Name; LastSelected = SelectedAvatar; } UpdateMotives(); } }
public int RunCommands(List <VMArchitectureCommand> commands, bool transient) { int cost = 0; //negative for sellback; int pdCount = 0; ushort pdVal = 0; VMAvatar lastAvatar = null; for (var i = 0; i < commands.Count; i++) { var com = commands[i]; var avaEnt = Context.VM.Entities.FirstOrDefault(x => x.PersistID == com.CallerUID); if ((avaEnt == null || avaEnt is VMGameObject) && !transient) { return(0); //we need an avatar to run a command from net } var avatar = (transient)? null : (VMAvatar)avaEnt; lastAvatar = avatar; var styleInd = -1; var walls = Content.Content.Get().WorldWalls; walls.WallStyleToIndex.TryGetValue(com.style, out styleInd); //if patterns are invalid, don't do anything. switch (com.Type) { case VMArchitectureCommandType.WALL_LINE: if (styleInd == -1) { break; //MUST be purchasable style } var lstyle = walls.GetWallStyle(com.style); var nwCount = VMArchitectureTools.DrawWall(this, new Point(com.x, com.y), com.x2, com.y2, com.pattern, com.style, com.level, false); if (nwCount > 0) { cost += nwCount * lstyle.Price; if (avatar != null) { Context.VM.SignalChatEvent(new VMChatEvent(avatar.PersistID, VMChatEventType.Arch, avatar.Name, Context.VM.GetUserIP(avatar.PersistID), "placed " + nwCount + " walls." )); } } break; case VMArchitectureCommandType.WALL_DELETE: var dwCount = VMArchitectureTools.EraseWall(this, new Point(com.x, com.y), com.x2, com.y2, com.pattern, com.style, com.level); if (dwCount > 0) { cost -= 7 * dwCount; if (avatar != null) { Context.VM.SignalChatEvent(new VMChatEvent(avatar.PersistID, VMChatEventType.Arch, avatar.Name, Context.VM.GetUserIP(avatar.PersistID), "erased " + dwCount + " walls." )); } } break; case VMArchitectureCommandType.WALL_RECT: if (styleInd == -1) { break; //MUST be purchasable style } var rstyle = walls.GetWallStyle(com.style); var rwCount = VMArchitectureTools.DrawWallRect(this, new Rectangle(com.x, com.y, com.x2, com.y2), com.pattern, com.style, com.level); if (rwCount > 0) { cost += rwCount * rstyle.Price; if (avatar != null) { Context.VM.SignalChatEvent(new VMChatEvent(avatar.PersistID, VMChatEventType.Arch, avatar.Name, Context.VM.GetUserIP(avatar.PersistID), "placed " + rwCount + " walls (rect)." )); } } break; case VMArchitectureCommandType.PATTERN_FILL: var pattern = GetPatternRef(com.pattern); if (pattern == null && com.pattern != 0) { break; } var pfCount = VMArchitectureTools.WallPatternFill(this, new Point(com.x, com.y), com.pattern, com.level); if (pfCount.Total > 0) { cost -= pfCount.Cost - pfCount.Cost / 5; cost += (pattern == null) ? 0 : pattern.Price * pfCount.Total; if (avatar != null) { Context.VM.SignalChatEvent(new VMChatEvent(avatar.PersistID, VMChatEventType.Arch, avatar.Name, Context.VM.GetUserIP(avatar.PersistID), "pattern filled " + pfCount + " walls with pattern #" + com.pattern )); } } break; case VMArchitectureCommandType.PATTERN_DOT: var pdpattern = GetPatternRef(com.pattern); if (pdpattern == null && com.pattern != 0) { break; } var dot = VMArchitectureTools.WallPatternDot(this, new Point(com.x, com.y), com.pattern, com.x2, com.y2, com.level); pdVal = com.pattern; if (dot.Total > -1) { cost -= dot.Cost - dot.Cost / 5; cost += (pdpattern == null) ? 0 : pdpattern.Price; pdCount++; } break; case VMArchitectureCommandType.FLOOR_FILL: var ffpattern = GetFloorRef(com.pattern); if (ffpattern == null && com.pattern != 0) { break; } var ffCount = VMArchitectureTools.FloorPatternFill(this, new Point(com.x, com.y), com.pattern, com.level); if (ffCount.Total > 0) { cost -= (ffCount.Cost - ffCount.Cost / 5) / 2; cost += (ffpattern == null) ? 0 : ffpattern.Price * ffCount.Total / 2; if (avatar != null) { Context.VM.SignalChatEvent(new VMChatEvent(avatar.PersistID, VMChatEventType.Arch, avatar.Name, Context.VM.GetUserIP(avatar.PersistID), "floor filled " + ffCount.Total / 2f + " with pattern #" + com.pattern )); } } break; case VMArchitectureCommandType.FLOOR_RECT: var frpattern = GetFloorRef(com.pattern); if (frpattern == null && com.pattern != 0) { break; } var frCount = VMArchitectureTools.FloorPatternRect(this, new Rectangle(com.x, com.y, com.x2, com.y2), com.style, com.pattern, com.level); if (frCount.Total > 0) { cost -= (frCount.Cost - frCount.Cost / 5) / 2; cost += (frpattern == null) ? 0 : frpattern.Price * frCount.Total / 2; if (avatar != null) { Context.VM.SignalChatEvent(new VMChatEvent(avatar.PersistID, VMChatEventType.Arch, avatar.Name, Context.VM.GetUserIP(avatar.PersistID), "placed " + frCount.Total / 2f + " tiles with pattern #" + com.pattern )); } } break; } } if (lastAvatar != null && pdCount > 0) { Context.VM.SignalChatEvent(new VMChatEvent(lastAvatar.PersistID, VMChatEventType.Arch, lastAvatar.Name, Context.VM.GetUserIP(lastAvatar.PersistID), "pattern dotted " + pdCount + " walls with pattern #" + pdVal )); } return(cost); }
public void Load(VMMarshal input) { var oldWorld = Context.World; Context = new VMContext(input.Context, Context); Context.Globals = FSO.Content.Content.Get().WorldObjectGlobals.Get("global"); Context.VM = this; Context.Architecture.RegenRoomMap(); Context.RegeneratePortalInfo(); if (Entities != null) //free any object resources here. { foreach (var obj in Entities) { if (obj.HeadlineRenderer != null) { obj.HeadlineRenderer.Dispose(); } } } Entities = new List <VMEntity>(); ObjectsById = new Dictionary <short, VMEntity>(); foreach (var ent in input.Entities) { VMEntity realEnt; var objDefinition = FSO.Content.Content.Get().WorldObjects.Get(ent.GUID); if (ent is VMAvatarMarshal) { var avatar = new VMAvatar(objDefinition); avatar.Load((VMAvatarMarshal)ent); if (UseWorld) { Context.Blueprint.AddAvatar((AvatarComponent)avatar.WorldUI); } realEnt = avatar; } else { var worldObject = new ObjectComponent(objDefinition); var obj = new VMGameObject(objDefinition, worldObject); obj.Load((VMGameObjectMarshal)ent); Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI); Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position); obj.Position = obj.Position; realEnt = obj; } realEnt.GenerateTreeByName(Context); Entities.Add(realEnt); ObjectsById.Add(ent.ObjectID, realEnt); } int i = 0; foreach (var ent in input.Entities) { var threadMarsh = input.Threads[i]; var realEnt = Entities[i++]; realEnt.Thread = new VMThread(threadMarsh, Context, realEnt); if (realEnt is VMAvatar) { ((VMAvatar)realEnt).LoadCrossRef((VMAvatarMarshal)ent, Context); } else { ((VMGameObject)realEnt).LoadCrossRef((VMGameObjectMarshal)ent, Context); } } foreach (var multi in input.MultitileGroups) { new VMMultitileGroup(multi, Context); //should self register } foreach (var ent in Entities) { ent.PositionChange(Context, true); } GlobalState = input.GlobalState; ObjectId = input.ObjectId; //just a few final changes to refresh everything, and avoid signalling objects var clock = Context.Clock; Context.Architecture.SetTimeOfDay(clock.Hours / 24.0 + clock.Minutes / (24.0 * 60) + clock.Seconds / (24.0 * 60 * 60)); Context.Architecture.RegenRoomMap(); Context.RegeneratePortalInfo(); Context.Architecture.WallDirtyState(input.Context.Architecture); if (OnFullRefresh != null) { OnFullRefresh(); } }