public override void Update(UpdateState state) { base.Update(state); lock (AnimationRequests) { while (TargetTile != null && AnimationRequests.Count > 0) { var anim = AnimationRequests.Dequeue(); var animation = FSO.Content.Content.Get().AvatarAnimations.Get(anim + ".anim"); if (animation != null) { var astate = new VMAnimationState(animation, false); astate.Loop = true; ((VMAvatar)TargetTile).Animations.Clear(); ((VMAvatar)TargetTile).Animations.Add(astate); } } } state.SharedData["ExternalDraw"] = true; }
public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args) { var operand = (VMAnimateSimOperand)args; var avatar = (VMAvatar)context.Caller; Animation animation = null; if (operand.AnimationID == 0) { //reset avatar.Animations.Clear(); var posture = avatar.GetPersonData(VMPersonDataVariable.Posture); if (posture != 1 && posture != 2) posture = 3; //sit and kneel are 1 and 2, 0 is stand but in walk animations it's 3. //todo: swimming?? animation = FSO.Content.Content.Get().AvatarAnimations.Get(avatar.WalkAnimations[posture] + ".anim"); var state = new VMAnimationState(animation, operand.PlayBackwards); state.Loop = true; avatar.Animations.Add(state); if (avatar.GetSlot(0) != null) //if we're carrying something, set carry animation to default carry. { avatar.CarryAnimationState = new VMAnimationState(FSO.Content.Content.Get().AvatarAnimations.Get("a2o-rarm-carry-loop.anim"), false); } else avatar.CarryAnimationState = null; return VMPrimitiveExitCode.GOTO_TRUE; } animation = VMMemory.GetAnimation(context, operand.Source, operand.AnimationID); if (animation == null){ return VMPrimitiveExitCode.GOTO_TRUE; } if (operand.Mode == 3) //stop standard carry, then play and wait avatar.CarryAnimationState = null; if (operand.Mode == 0 || operand.Mode == 3) //Play and Wait { /** Are we starting the animation or progressing it? **/ if (avatar.CurrentAnimationState == null || avatar.CurrentAnimationState.Anim != animation) { /** Start it **/ avatar.Animations.Clear(); avatar.Animations.Add(new VMAnimationState(animation, operand.PlayBackwards)); avatar.Avatar.LeftHandGesture = SimHandGesture.Idle; avatar.Avatar.RightHandGesture = SimHandGesture.Idle; return VMPrimitiveExitCode.CONTINUE_NEXT_TICK; } else { if (avatar.CurrentAnimationState.EndReached) { avatar.Animations.Clear(); return VMPrimitiveExitCode.GOTO_TRUE; } else if (avatar.CurrentAnimationState.EventFired) { avatar.CurrentAnimationState.EventFired = false; //clear fired flag if (operand.StoreFrameInLocal) { VMMemory.SetVariable(context, VMVariableScope.Local, operand.LocalEventNumber, avatar.CurrentAnimationState.EventCode); } else { VMMemory.SetVariable(context, VMVariableScope.Parameters, 0, avatar.CurrentAnimationState.EventCode); } return VMPrimitiveExitCode.GOTO_FALSE; } else { return VMPrimitiveExitCode.CONTINUE_NEXT_TICK; } } } else if (operand.Mode == 2) //set custom carry animation { avatar.CarryAnimationState = new VMAnimationState(animation, false); return VMPrimitiveExitCode.GOTO_TRUE; } else return VMPrimitiveExitCode.GOTO_TRUE; }
public override void PlaceInSlot(VMEntity obj, int slot, bool cleanOld, VMContext context) { if (cleanOld) obj.PrePositionChange(context); if (!obj.GhostImage) { HandObject = obj; CarryAnimationState = new VMAnimationState(FSO.Content.Content.Get().AvatarAnimations.Get("a2o-rarm-carry-loop.anim"), false); //set default carry animation obj.Container = this; obj.ContainerSlot = (short)slot; } if (UseWorld) { obj.WorldUI.Container = this.WorldUI; obj.WorldUI.ContainerSlot = slot; obj.Position = Position; //TODO: is physical position the same as the slot offset position? if (obj.WorldUI is ObjectComponent) { var objC = (ObjectComponent)obj.WorldUI; objC.ForceDynamic = true; } } }
public virtual void Load(VMAvatarMarshal input) { base.Load(input); Animations = new List<VMAnimationState>(); foreach (var anim in input.Animations) Animations.Add(new VMAnimationState(anim)); CarryAnimationState = (input.CarryAnimationState == null) ? null : new VMAnimationState(input.CarryAnimationState); Name = input.Name; Message = input.Message; MessageTimeout = input.MessageTimeout; MotiveChanges = input.MotiveChanges; PersonData = input.PersonData; MotiveData = input.MotiveData; RadianDirection = input.RadianDirection; DefaultSuits = input.DefaultSuits; BoundAppearances = new HashSet<string>(input.BoundAppearances); foreach (var aprN in BoundAppearances) { var apr = FSO.Content.Content.Get().AvatarAppearances.Get(aprN); Avatar.AddAccessory(apr); } SkinTone = input.SkinTone; if (UseWorld) ((AvatarComponent)WorldUI).ObjectID = (ushort)ObjectID; }
public override void ClearSlot(int slot) { HandObject.Container = null; HandObject.ContainerSlot = -1; CarryAnimationState = null; if (UseWorld) { HandObject.WorldUI.Container = null; HandObject.WorldUI.ContainerSlot = 0; if (HandObject.WorldUI is ObjectComponent) { var objC = (ObjectComponent)HandObject.WorldUI; objC.ForceDynamic = false; } } HandObject = null; }
public VMPrimitiveExitCode Tick() { var avatar = (VMAvatar)Caller; avatar.Velocity = new Vector3(0, 0, 0); if (State != VMRoutingFrameState.FAILED && avatar.GetFlag(VMEntityFlags.InteractionCanceled) && avatar.GetPersonData(VMPersonDataVariable.NonInterruptable) == 0) { HardFail(VMRouteFailCode.Interrupted, null); return VMPrimitiveExitCode.CONTINUE; } if (WaitTime > 0) { if (Velocity > 0) Velocity--; if (avatar.Animations.Count < 3) StartWalkAnimation(); avatar.Animations[0].Weight = (8 - Velocity) / 8f; avatar.Animations[1].Weight = (Velocity / 8f) * 0.66f; avatar.Animations[2].Weight = (Velocity / 8f) * 0.33f; WaitTime--; Timeout--; if (Timeout <= 0) { //try again. not sure if we should reset timeout for the new route SoftFail(VMRouteFailCode.NoPath, null); if (State != VMRoutingFrameState.FAILED) { Velocity = 0; State = VMRoutingFrameState.WALKING; } } else return VMPrimitiveExitCode.CONTINUE_NEXT_TICK; } if (RoomRouteInvalid && State != VMRoutingFrameState.BEGIN_TURN && State != VMRoutingFrameState.END_TURN) { RoomRouteInvalid = false; IgnoredRooms.Clear(); WalkTo = null; //reset routing state if (!DoRoomRoute(CurRoute)) { if (CurRoute != null) SoftFail(VMRouteFailCode.NoRoomRoute, null); else HardFail(VMRouteFailCode.NoRoomRoute, null); } else if (Rooms.Count > 0) { State = VMRoutingFrameState.INITIAL; } } switch (State) { case VMRoutingFrameState.STAND_FUNC: if (Thread.LastStackExitCode == VMPrimitiveExitCode.RETURN_TRUE) { State = VMRoutingFrameState.INITIAL; if (avatar.GetPersonData(VMPersonDataVariable.Posture) == 1) avatar.SetPersonData(VMPersonDataVariable.Posture, 0); } else SoftFail(VMRouteFailCode.CantStand, null); return VMPrimitiveExitCode.CONTINUE; case VMRoutingFrameState.INITIAL: case VMRoutingFrameState.ROOM_PORTAL: //check if the room portal that just finished succeeded. if (State == VMRoutingFrameState.ROOM_PORTAL) { if (Thread.LastStackExitCode != VMPrimitiveExitCode.RETURN_TRUE) { IgnoredRooms.Add(CurrentPortal); State = VMRoutingFrameState.INITIAL; if (!DoRoomRoute(CurRoute)) { SoftFail(VMRouteFailCode.NoRoomRoute, null); //todo: reattempt room route with portal we tried removed. return VMPrimitiveExitCode.CONTINUE; } } } if (Rooms.Count > 0) { //push portal function of next portal CurrentPortal = Rooms.Pop(); var ent = VM.GetObjectById(CurrentPortal.ObjectID); State = VMRoutingFrameState.ROOM_PORTAL; if (!PushEntryPoint(15, ent)) //15 is portal function SoftFail(VMRouteFailCode.NoRoomRoute, null); //could not execute portal function return VMPrimitiveExitCode.CONTINUE; } //if we're here, room route is OK. start routing to a destination. if (Choices == null) { //perform slot parse. if (Slot == null) { HardFail(VMRouteFailCode.Unknown, null); return VMPrimitiveExitCode.CONTINUE; //this should never happen. If it does, someone has used the routing system incorrectly. } var parser = new VMSlotParser(Slot); Choices = parser.FindAvaliableLocations(Target, VM.Context, avatar); if (Choices.Count == 0) { HardFail(parser.FailCode, parser.Blocker); return VMPrimitiveExitCode.CONTINUE; } else { CurRoute = Choices[0]; Choices.RemoveAt(0); } } //do we need to sit in a seat? it should take over. if (CurRoute.Chair != null) { if (!AttemptedChair) { AttemptedChair = true; if (PushEntryPoint(26, CurRoute.Chair)) return VMPrimitiveExitCode.CONTINUE; else { SoftFail(VMRouteFailCode.CantSit, null); return VMPrimitiveExitCode.CONTINUE; } } else { if (Thread.LastStackExitCode == VMPrimitiveExitCode.RETURN_TRUE) return VMPrimitiveExitCode.RETURN_TRUE; else { SoftFail(VMRouteFailCode.CantSit, null); return VMPrimitiveExitCode.CONTINUE; } } } //If we are sitting, and the target is not this seat we need to call the stand function on the object we are contained within. if (avatar.GetPersonData(VMPersonDataVariable.Posture) == 1) { State = VMRoutingFrameState.STAND_FUNC; //push it onto our stack, except now the portal owns our soul! when we are returned to we can evaluate the result and determine if the route failed. var chair = Caller.Container; if (chair == null) avatar.SetPersonData(VMPersonDataVariable.Posture, 0); //we're sitting, but are not bound to a chair. Just instantly get up.. else { if (!PushEntryPoint(27, chair)) //27 is stand. TODO: set up an enum for these HardFail(VMRouteFailCode.CantStand, null); return VMPrimitiveExitCode.CONTINUE; } } //no chair, we just need to walk to the spot. Start the within-room routing. if (WalkTo == null) { if (!AttemptWalk()) { SoftFail(VMRouteFailCode.NoPath, null); return VMPrimitiveExitCode.CONTINUE; } } if (State != VMRoutingFrameState.TURN_ONLY) BeginWalk(); return VMPrimitiveExitCode.CONTINUE; case VMRoutingFrameState.FAILED: return VMPrimitiveExitCode.RETURN_FALSE; case VMRoutingFrameState.TURN_ONLY: return (EndWalk()) ? VMPrimitiveExitCode.RETURN_TRUE : VMPrimitiveExitCode.CONTINUE; case VMRoutingFrameState.SHOOED: StartWalkAnimation(); State = VMRoutingFrameState.WALKING; return VMPrimitiveExitCode.CONTINUE; case VMRoutingFrameState.BEGIN_TURN: case VMRoutingFrameState.END_TURN: if (avatar.CurrentAnimationState.EndReached) { if (State == VMRoutingFrameState.BEGIN_TURN) { State = VMRoutingFrameState.WALKING; WalkDirection = TargetDirection; avatar.RadianDirection = (float)TargetDirection; StartWalkAnimation(); return VMPrimitiveExitCode.CONTINUE; } else { if (!CurRoute.FaceAnywhere) avatar.RadianDirection = CurRoute.RadianDirection; //reset animation, so that we're facing the correct direction afterwards. avatar.Animations.Clear(); var animation = FSO.Content.Content.Get().AvatarAnimations.Get(avatar.WalkAnimations[3] + ".anim"); var state = new VMAnimationState(animation, false); state.Loop = true; avatar.Animations.Add(state); return VMPrimitiveExitCode.RETURN_TRUE; //we are here! } } else { avatar.RadianDirection += TurnTweak; //while we're turning, adjust our direction return VMPrimitiveExitCode.CONTINUE_NEXT_TICK; } case VMRoutingFrameState.WALKING: if (WalkTo == null) { if (!AttemptWalk()) { SoftFail(VMRouteFailCode.NoPath, null); } return VMPrimitiveExitCode.CONTINUE; } if (WalkTo.Count == 0 && MoveTotalFrames - MoveFrames <= 28 && CanPortalTurn()) //7+6+5+4... { //tail off if (Velocity <= 0) Velocity = 1; if (Velocity > 1) Velocity--; } else { //get started if (Velocity < 8) Velocity++; } avatar.Animations[0].Weight = (8 - Velocity) / 8f; avatar.Animations[1].Weight = (Velocity / 8f) * 0.66f; avatar.Animations[2].Weight = (Velocity / 8f) * 0.33f; MoveFrames += Velocity; if (MoveFrames >= MoveTotalFrames) { MoveFrames = MoveTotalFrames; //move us to the final spot, then attempt an advance. } //normal sims can move 0.05 units in a frame. if (TurnFrames > 0) { avatar.RadianDirection = (float)(TargetDirection + DirectionUtils.Difference(TargetDirection, WalkDirection) * (TurnFrames / 10.0)); TurnFrames--; } else avatar.RadianDirection = (float)TargetDirection; var diff = CurrentWaypoint - PreviousPosition; diff.x = (short)((diff.x * MoveFrames) / MoveTotalFrames); diff.y = (short)((diff.y * MoveFrames) / MoveTotalFrames); var storedDir = avatar.RadianDirection; var result = Caller.SetPosition(PreviousPosition + diff, Direction.NORTH, VM.Context); avatar.RadianDirection = storedDir; if (result.Status != VMPlacementError.Success && result.Status != VMPlacementError.CantBeThroughWall) { //route failure, either something changed or we hit an avatar //on both cases try again, but if we hit an avatar then detect if they have a routing frame and stop us for a bit. //we stop the first collider because in most cases they're walking across our walk direction and the problem will go away after a second once they're past. // //if we need to route around a stopped avatar we add them to our "avatars to consider" set. bool routeAround = true; VMRoutingFrame colRoute = null; if (result.Object != null && result.Object is VMAvatar) { var colAvatar = (VMAvatar)result.Object; var colTopFrame = colAvatar.Thread.Stack.LastOrDefault(); //we already attempted to move around this avatar... if this happens too much give up. if (AvatarsToConsider.Contains(colAvatar) && --Retries <= 0) { SoftFail(VMRouteFailCode.NoPath, avatar); return VMPrimitiveExitCode.CONTINUE; } if (colTopFrame != null && colTopFrame is VMRoutingFrame) { colRoute = (VMRoutingFrame)colTopFrame; routeAround = (colRoute.WaitTime > 0); } if (routeAround) AvatarsToConsider.Add(colAvatar); } if (result.Object == null || result.Object is VMGameObject) { //this should not happen often. An object or other feature has blocked our path due to some change in its position. //repeated occurances indicate that we are stuck in something. //todo: is this safe for the robot lot? if (--Retries <= 0) { SoftFail(VMRouteFailCode.NoPath, avatar); return VMPrimitiveExitCode.CONTINUE; } } if (routeAround) { var oldWalk = new LinkedList<Point>(WalkTo); if (AttemptWalk()) return VMPrimitiveExitCode.CONTINUE; else { //failed to walk around the object if (result.Object is VMAvatar) { WalkTo = oldWalk; //if they're a person, shoo them away. //if they're in a routing frame we can push the tree directly onto their stack //otherwise we push an interaction and just hope they move (todo: does tso do this?) //DO NOT push tree if: // - sim is already being shooed. (the parent of the top routing frame is in state "SHOOED" or shoo interaction is present) // - we are being shooed. // - sim is waiting on someone they just shooed. (presumably can move out of our way once they finish waiting) //instead just wait a small duration and try again later. //cases where we cannot continue moving increase the retry count. if this is greater than RETRY_COUNT then we fail. //not sure how the original game works. if (CanShooAvatar((VMAvatar)result.Object)) { AvatarsToConsider.Remove((VMAvatar)result.Object); VMEntity callee = VM.Context.CreateObjectInstance(GOTO_GUID, new LotTilePos(result.Object.Position), Direction.NORTH).Objects[0]; if (colRoute != null) { colRoute.State = VMRoutingFrameState.SHOOED; colRoute.WalkTo = null; colRoute.AvatarsToConsider.Add(avatar); //just to make sure they don't try route through us. var tree = callee.GetBHAVWithOwner(SHOO_TREE, VM.Context); result.Object.Thread.ExecuteSubRoutine(colRoute, tree.bhav, tree.owner, new VMSubRoutineOperand()); WalkInterrupt(60); } else { callee.PushUserInteraction(SHOO_INTERACTION, result.Object, VM.Context); WalkInterrupt(60); } } else { WalkInterrupt(60); //wait for a little while, they're moving out of the way. } return VMPrimitiveExitCode.CONTINUE; } SoftFail(VMRouteFailCode.DestTileOccupied, result.Object); return VMPrimitiveExitCode.CONTINUE; } } else { WalkInterrupt(30); return VMPrimitiveExitCode.CONTINUE; } } Caller.VisualPosition = Vector3.Lerp(PreviousPosition.ToVector3(), CurrentWaypoint.ToVector3(), MoveFrames / (float)MoveTotalFrames); var velocity = Vector3.Lerp(PreviousPosition.ToVector3(), CurrentWaypoint.ToVector3(), Velocity / (float)MoveTotalFrames) - PreviousPosition.ToVector3(); velocity.Z = 0; avatar.Velocity = velocity; if (MoveTotalFrames == MoveFrames) { MoveTotalFrames = 0; while (MoveTotalFrames == 0) { var remains = AdvanceWaypoint(); if (!remains) { MoveTotalFrames = -1; if (EndWalk()) return VMPrimitiveExitCode.RETURN_TRUE; } } } return VMPrimitiveExitCode.CONTINUE_NEXT_TICK; } return VMPrimitiveExitCode.GOTO_FALSE; //??? }
private VMAnimationState PlayAnim(string name, VMAvatar avatar) { var animation = FSO.Content.Content.Get().AvatarAnimations.Get(name + ".anim"); var state = new VMAnimationState(animation, false); avatar.Animations.Add(state); return state; }
public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args) { var operand = (VMAnimateSimOperand)args; var avatar = (VMAvatar)context.Caller; Animation animation = null; if (operand.AnimationID == 0) { //reset avatar.Animations.Clear(); var posture = avatar.GetPersonData(VMPersonDataVariable.Posture); if (posture != 1 && posture != 2) posture = 3; //sit and kneel are 1 and 2, 0 is stand but in walk animations it's 3. //todo: swimming?? animation = FSO.Content.Content.Get().AvatarAnimations.Get(avatar.WalkAnimations[posture] + ".anim"); var state = new VMAnimationState(animation, operand.PlayBackwards); state.Loop = true; avatar.Animations.Add(state); if (avatar.GetSlot(0) != null) //if we're carrying something, set carry animation to default carry. { avatar.CarryAnimationState = new VMAnimationState(FSO.Content.Content.Get().AvatarAnimations.Get("a2o-rarm-carry-loop.anim"), false); } else avatar.CarryAnimationState = null; return VMPrimitiveExitCode.GOTO_TRUE; } animation = VMMemory.GetAnimation(context, operand.Source, operand.AnimationID); if (animation == null){ return VMPrimitiveExitCode.GOTO_TRUE; } if (operand.Mode == 3) //stop standard carry, then play and wait avatar.CarryAnimationState = null; if (operand.Mode == 0 || operand.Mode == 3) //Play and Wait { /** Are we starting the animation or progressing it? **/ if (avatar.CurrentAnimationState == null || avatar.CurrentAnimationState.Anim != animation) { /** Start it **/ avatar.Animations.Clear(); avatar.Animations.Add(new VMAnimationState(animation, operand.PlayBackwards)); avatar.Avatar.LeftHandGesture = SimHandGesture.Idle; avatar.Avatar.RightHandGesture = SimHandGesture.Idle; return VMPrimitiveExitCode.CONTINUE_NEXT_TICK; } else { var cAnim = avatar.CurrentAnimationState; //SPECIAL CASE: if we are ending the animation, and the number of events run < expected events //forcefully run those events, with id as their event number. (required for bath drain) if (cAnim.EndReached) { while (cAnim.EventsRun < operand.ExpectedEventCount) { cAnim.EventQueue.Add(cAnim.EventsRun++); } } if (cAnim.EventQueue.Count > 0) //favor events over end. do not want to miss any. { var code = cAnim.EventQueue[0]; cAnim.EventQueue.RemoveAt(0); if (operand.StoreFrameInLocal) VMMemory.SetVariable(context, VMVariableScope.Local, operand.LocalEventNumber, code); else VMMemory.SetVariable(context, VMVariableScope.Parameters, 0, code); return VMPrimitiveExitCode.GOTO_FALSE; } else if (cAnim.EndReached) { avatar.Animations.Clear(); return VMPrimitiveExitCode.GOTO_TRUE; } else { return VMPrimitiveExitCode.CONTINUE_NEXT_TICK; } } } else if (operand.Mode == 2) //set custom carry animation { avatar.CarryAnimationState = new VMAnimationState(animation, false); return VMPrimitiveExitCode.GOTO_TRUE; } else return VMPrimitiveExitCode.GOTO_TRUE; }