public void SetState(Network.Structure.RawMotionState state) { CurrentHoldKey = state.CurrentHoldKey; CurrentStyle = (uint)state.CurrentStyle; if (CurrentStyle == 0) { CurrentStyle = (uint)MotionCommand.NonCombat; } ForwardCommand = (uint)state.ForwardCommand; if (ForwardCommand == 0) { ForwardCommand = (uint)MotionCommand.Ready; } ForwardHoldKey = state.ForwardHoldKey; ForwardSpeed = state.ForwardSpeed; // todo: verifications if (ForwardSpeed == 0) { ForwardSpeed = 1.0f; } SideStepCommand = (uint)state.SidestepCommand; SideStepHoldKey = state.SidestepHoldKey; SideStepSpeed = state.SidestepSpeed; if (SideStepSpeed == 0) { SideStepSpeed = 1.0f; } TurnCommand = (uint)state.TurnCommand; TurnHoldKey = state.TurnHoldKey; TurnSpeed = state.TurnSpeed; if (TurnSpeed == 0) { TurnSpeed = 1.0f; } }
public void BeginMoveForward() { //Console.WriteLine("BeginMoveForward"); if (PhysicsObj == null) { CancelMoveTo(WeenieError.NoPhysicsObject); return; } var dist = GetCurrentDistance(); var heading = PhysicsObj.Position.heading(CurrentTargetPosition) - PhysicsObj.get_heading(); if (Math.Abs(heading) < PhysicsGlobals.EPSILON) { heading = 0.0f; } if (heading < -PhysicsGlobals.EPSILON) { heading += 360.0f; } uint motion = 0; bool moveAway = false; HoldKey holdKey = HoldKey.Invalid; MovementParams.get_command(dist, heading, ref motion, ref holdKey, ref moveAway); if (motion == 0) { RemovePendingActionsHead(); BeginNextNode(); return; } var movementParams = new MovementParameters(); movementParams.HoldKeyToApply = holdKey; movementParams.CancelMoveTo = false; movementParams.Speed = MovementParams.Speed; var result = _DoMotion(motion, movementParams); if (result != WeenieError.None) { CancelMoveTo(result); return; } CurrentCommand = motion; MovingAway = moveAway; MovementParams.HoldKeyToApply = holdKey; PreviousDistance = dist; PreviousDistanceTime = PhysicsTimer.CurrentTime; OriginalDistance = dist; OriginalDistanceTime = PhysicsTimer.CurrentTime; }
private GameObject getHoldKeyInstance(int keySpawnNodeCounter, float keySpawnDistance) { GameObject newKey = Instantiate(GameController.getInstance().holdKeyPrefab); HoldKey holdKey = newKey.GetComponent <HoldKey> (); holdKey.setHoldLineLength(arrow.Keys [keyCounter].Duration * speed); holdKey.setFollowingNodes(arrow.nodesToVector3().GetRange(keySpawnNodeCounter, arrow.Nodes.Count - keySpawnNodeCounter)); holdKey.setOwnerArrow(transform); return(newKey); }
public void MoveToPosition(Position position, MovementParameters movementParams) { //Console.WriteLine("MoveToPosition"); if (PhysicsObj == null) { return; } PhysicsObj.StopCompletely(false); CurrentTargetPosition = new Position(position); SoughtObjectRadius = 0.0f; var distance = GetCurrentDistance(); var headingDiff = PhysicsObj.Position.heading(position) - PhysicsObj.get_heading(); if (Math.Abs(headingDiff) < PhysicsGlobals.EPSILON) { headingDiff = 0.0f; } if (headingDiff < -PhysicsGlobals.EPSILON) { headingDiff += 360.0f; } HoldKey holdKey = HoldKey.Invalid; uint command = 0; bool moveAway = false; movementParams.get_command(distance, headingDiff, ref command, ref holdKey, ref moveAway); if (command != 0) { AddTurnToHeadingNode(PhysicsObj.Position.heading(position)); AddMoveToPositionNode(); } if (MovementParams.UseFinalHeading) { AddTurnToHeadingNode(movementParams.DesiredHeading); } SoughtPosition = new Position(position); StartingPosition = new Position(PhysicsObj.Position); MovementType = MovementType.MoveToPosition; MovementParams = new MovementParameters(movementParams); //var flags = (MovementParamFlags)0xFFFFFF7F; // unset Sticky? //MovementParams.Flags = MovementParams.Flags & flags; MovementParams.Sticky = false; BeginNextNode(); }
public RawMotionState(RawMotionState _base, RawMotionState rawState) { InitDefaults(); Actions = _base.Actions; CurrentStyle = _base.CurrentStyle; CurrentHoldKey = rawState.CurrentHoldKey; ForwardCommand = rawState.ForwardCommand; SideStepCommand = rawState.SideStepCommand; TurnCommand = rawState.TurnCommand; }
public void BeginMoveForward() { if (PhysicsObj == null) { CancelMoveTo(0x8); return; } var dist = GetCurrentDistance(); var heading = PhysicsObj.Position.heading(CurrentTargetPosition) - PhysicsObj.get_heading(); if (Math.Abs(heading) < PhysicsGlobals.EPSILON) { heading = 0.0f; } if (heading < -PhysicsGlobals.EPSILON) { heading += 360.0f; } uint motion = 0; bool moveAway = false; HoldKey holdKey = HoldKey.Invalid; MovementParams.get_command(dist, heading, ref motion, ref holdKey, ref moveAway); if (motion == 0) { PendingActions.Clear(); BeginNextNode(); return; } var movementParams = new MovementParameters(); movementParams.HoldKeyToApply = holdKey; movementParams.CancelMoveTo = false; movementParams.Speed = MovementParams.Speed; var sequence = _DoMotion(motion, movementParams); if (sequence.ID != 0) { CancelMoveTo(sequence.ID); return; } CurrentCommand = motion; MovingAway = moveAway; MovementParams.HoldKeyToApply = holdKey; PreviousDistance = dist; PreviousDistanceTime = Timer.CurrentTime; OriginalDistance = dist; OriginalDistanceTime = Timer.CurrentTime; }
public void MoveToPosition(Position position, MovementParameters movementParams) { if (PhysicsObj == null) { return; } PhysicsObj.StopCompletely(false); CurrentTargetPosition = position; SoughtObjectRadius = 0.0f; var distance = GetCurrentDistance(); var headingDiff = PhysicsObj.Position.heading(position) - PhysicsObj.get_heading(); if (Math.Abs(headingDiff) < PhysicsGlobals.EPSILON) { headingDiff = 0.0f; } if (headingDiff < -PhysicsGlobals.EPSILON) { headingDiff += 360.0f; } HoldKey holdKey = HoldKey.Invalid; uint command = 0; bool moveAway = false; movementParams.get_command(distance, headingDiff, ref command, ref holdKey, ref moveAway); if (command != 0) { AddTurnToHeadingNode(PhysicsObj.Position.heading(position)); AddMoveToPositionNode(); } if (MovementParams.UseFinalHeading) { AddTurnToHeadingNode(movementParams.DesiredHeading); } SoughtPosition = position; StartingPosition = PhysicsObj.Position; MovementType = MovementType.MoveToPosition; MovementParams = movementParams; MovementParams.Bitfield &= 0xFFFFFF7F; BeginNextNode(); }
public void MoveToObject_Internal(Position targetPosition, Position interpolatedPosition) { //Console.WriteLine("MoveToObject_Internal"); if (PhysicsObj == null) { CancelMoveTo(WeenieError.NoPhysicsObject); return; } SoughtPosition = new Position(interpolatedPosition); CurrentTargetPosition = new Position(targetPosition); var iHeading = PhysicsObj.Position.heading(interpolatedPosition); var heading = iHeading - PhysicsObj.get_heading(); var dist = GetCurrentDistance(); if (Math.Abs(heading) < PhysicsGlobals.EPSILON) { heading = 0.0f; } if (heading < -PhysicsGlobals.EPSILON) { heading += 360.0f; } HoldKey holdKey = HoldKey.Invalid; uint motionID = 0; bool moveAway = false; MovementParams.get_command(dist, heading, ref motionID, ref holdKey, ref moveAway); if (motionID != 0) { AddTurnToHeadingNode(iHeading); AddMoveToPositionNode(); } if (MovementParams.UseFinalHeading) { var dHeading = iHeading + MovementParams.DesiredHeading; if (dHeading >= 360.0f) { dHeading -= 360.0f; } AddTurnToHeadingNode(dHeading); } Initialized = true; BeginNextNode(); }
public void InitDefaults() { Actions = new List <ActionNode>(); CurrentHoldKey = HoldKey.None; CurrentStyle = (uint)MotionCommand.NonCombat; ForwardCommand = (uint)MotionCommand.Ready; ForwardHoldKey = HoldKey.Invalid; ForwardSpeed = 1.0f; SideStepCommand = 0; SideStepHoldKey = HoldKey.Invalid; SideStepSpeed = 1.0f; TurnCommand = 0; TurnHoldKey = HoldKey.Invalid; TurnSpeed = 1.0f; }
public void InitDefaults() { Actions = new List <ActionNode>(); CurrentHoldKey = HoldKey.None; CurrentStyle = 0x8000003D; ForwardCommand = 0x41000003; ForwardHoldKey = HoldKey.Invalid; ForwardSpeed = 1.0f; SideStepCommand = 0; SideStepHoldKey = HoldKey.Invalid; SideStepSpeed = 1.0f; TurnCommand = 0; TurnHoldKey = HoldKey.Invalid; TurnSpeed = 1.0f; }
public void SetHoldKey(HoldKey key, bool cancelMoveTo) { if (key == RawState.CurrentHoldKey) { return; } switch (key) { case HoldKey.None: if (RawState.CurrentHoldKey == HoldKey.Run) { RawState.CurrentHoldKey = HoldKey.None; apply_current_movement(cancelMoveTo, true); } break; } }
public void adjust_motion(ref uint motion, ref float speed, HoldKey holdKey) { if (WeenieObj != null && !WeenieObj.IsCreature()) { return; } switch (motion) { case (uint)MotionCommand.RunForward: return; case (uint)MotionCommand.WalkBackwards: motion = (uint)MotionCommand.WalkForward; speed *= -BackwardsFactor; break; case (uint)MotionCommand.TurnLeft: motion = (uint)MotionCommand.TurnRight; speed *= -1.0f; break; case (uint)MotionCommand.SideStepLeft: motion = (uint)MotionCommand.SideStepRight; speed *= -1.0f; break; } if (motion == (uint)MotionCommand.SideStepRight) { speed *= SidestepFactor * (WalkAnimSpeed / SidestepAnimSpeed); } if (holdKey == HoldKey.Invalid) { holdKey = RawState.CurrentHoldKey; } if (holdKey == HoldKey.Run) { apply_run_to_command(ref motion, ref speed); } }
public void get_command(float dist, float heading, ref int motion, ref HoldKey holdKey, ref bool movingAway) { if (MoveTowards || !MoveAway) { if (MoveAway) { towards_and_away(dist, heading, ref motion, ref movingAway); } else { if (dist > DistanceToObject) { motion = 0x45000005; movingAway = false; } else { motion = 0; } } } else if (MoveAway) { if (dist < MinDistance) { motion = 0x45000005; movingAway = true; } else { motion = 0; } } if (CanRun && (!CanWalk || dist - DistanceToObject > WalkRunThreshold)) { holdKey = HoldKey.Run; } else { holdKey = HoldKey.None; } }
public void adjust_motion(uint motion, float speed, HoldKey holdKey) { if (WeenieObj != null && !WeenieObj.IsCreature()) { return; } switch (motion) { case 0x44000007: return; case 0x45000006: motion = 0x45000005; speed *= -BackwardsFactor; break; case 0x6400000E: motion = 0x6500000D; speed *= -1.0f; break; case 0x65000010: motion = 0x6500000F; speed *= -1.0f; break; case 0x6500000F: speed = speed * SidestepFactor * (WalkAnimSpeed / SidestepAnimSpeed); break; } if (holdKey == HoldKey.Invalid) { holdKey = RawState.CurrentHoldKey; } if (holdKey == HoldKey.Run) { apply_run_to_command(motion, speed); } }
public MovementParameters() { MinDistance = Default_MinDistance; DistanceToObject = Default_DistanceToObject; FailDistance = Default_FailDistance; Speed = Default_Speed; WalkRunThreshold = Default_WalkRunThreshold; HoldKeyToApply = HoldKey.Invalid; StopCompletely = true; CancelMoveTo = true; ModifyInterpretedState = true; ModifyRawState = true; SetHoldKey = true; UseSpheres = true; MoveTowards = true; CanWalkBackwards = true; CanSidestep = true; CanRun = true; CanWalk = true; Bitfield = 0x1EE0F; // todo: union of bools }
// Use this for initialization void Start() { Utilities.audioSource = GetComponent <AudioSource>(); Utilities.collectedSound = collectedSound; Utilities.p1_selector_mat = p1_selector_mat; Utilities.p1_light_mat = p1_light_mat; Utilities.p2_selector_mat = p2_selector_mat; Utilities.p2_light_mat = p2_light_mat; Utilities.p3_selector_mat = p3_selector_mat; Utilities.p3_light_mat = p3_light_mat; Utilities.p4_selector_mat = p4_selector_mat; Utilities.p4_light_mat = p4_light_mat; Utilities.arrow_mat = arrow_mat; Utilities.arrow_mat_white = arrow_mat_white; Utilities.angle_arrow_mat = angle_arrow_mat; Utilities.opp_angle_arrow_mat = opp_angle_arrow_mat; Utilities.text_packet_mat = text_packet_mat; Utilities.text_packet2_mat = text_packet2_mat; Utilities.text_packet3_mat = text_packet3_mat; Utilities.board_mat = board_mat; Utilities.overlay_mat = overlay_mat; limit = new Vector2(rows, columns); quit = new HoldKey(KeyCode.Q, HOLD_KEY_TIME); pause = new HoldKey(KeyCode.P, HOLD_KEY_TIME); start = new HoldKey(KeyCode.S, HOLD_KEY_TIME); keyOne = new HoldKey(KeyCode.Alpha1, HOLD_KEY_TIME); keyTwo = new HoldKey(KeyCode.Alpha2, HOLD_KEY_TIME); keyThree = new HoldKey(KeyCode.Alpha3, HOLD_KEY_TIME); keyFour = new HoldKey(KeyCode.Alpha4, HOLD_KEY_TIME); addKeyboard = new HoldKey(KeyCode.A, HOLD_KEY_TIME); MakeBackground(); map1 = DefineMap1(); map2 = DefineMap2(); map3 = DefineMap3(); map4 = DefineMap4(); currentMap = map1; gameUI = new GameUI(); goToStartState(); }
public void MovePlayer_NonAutonomous(MotionCommand command, bool start, float speed, HoldKey holdKey) { if (start) { if (command == MotionCommand.Jump) { // vfptr[5].OnAction } else { // vfptr[19].OnAction } } else if (command == MotionCommand.Jump) { // vfptr[5].OnLoseFocus } else { // vfptr[19].OnLoseFocus } }
public void ApplyMotion(uint motion, MovementParameters movementParams) { switch (motion) { case 0x6500000D: case 0x6500000E: TurnCommand = motion; if (movementParams.SetHoldKey) { TurnHoldKey = HoldKey.Invalid; TurnSpeed = movementParams.Speed; } else { TurnHoldKey = movementParams.HoldKeyToApply; TurnSpeed = movementParams.Speed; } break; case 0x6500000F: case 0x65000010: SideStepCommand = motion; if (movementParams.SetHoldKey) { SideStepHoldKey = HoldKey.Invalid; SideStepSpeed = movementParams.Speed; } else { SideStepHoldKey = movementParams.HoldKeyToApply; SideStepSpeed = movementParams.Speed; } break; default: if ((motion & 0x40000000) != 0) { if (motion != 0x44000007) { ForwardCommand = motion; if (movementParams.SetHoldKey) { ForwardHoldKey = HoldKey.Invalid; ForwardSpeed = movementParams.Speed; } else { ForwardHoldKey = movementParams.HoldKeyToApply; ForwardSpeed = movementParams.Speed; } } } else if ((motion & 0x80000000) != 0) { if (CurrentStyle != motion) { ForwardCommand = 0x41000003; CurrentStyle = motion; } } else if ((motion & 0x10000000) != 0) { AddAction(motion, movementParams.Speed, movementParams.ActionStamp, movementParams.Autonomous); } break; } }
public void ApplyMotion(uint motion, MovementParameters movementParams) { switch (motion) { case (uint)MotionCommand.TurnRight: case (uint)MotionCommand.TurnLeft: TurnCommand = motion; if (movementParams.SetHoldKey) { TurnHoldKey = HoldKey.Invalid; TurnSpeed = movementParams.Speed; } else { TurnHoldKey = movementParams.HoldKeyToApply; TurnSpeed = movementParams.Speed; } break; case (uint)MotionCommand.SideStepRight: case (uint)MotionCommand.SideStepLeft: SideStepCommand = motion; if (movementParams.SetHoldKey) { SideStepHoldKey = HoldKey.Invalid; SideStepSpeed = movementParams.Speed; } else { SideStepHoldKey = movementParams.HoldKeyToApply; SideStepSpeed = movementParams.Speed; } break; default: if ((motion & (uint)CommandMask.SubState) != 0) { if (motion != (uint)MotionCommand.RunForward) { ForwardCommand = motion; if (movementParams.SetHoldKey) { ForwardHoldKey = HoldKey.Invalid; ForwardSpeed = movementParams.Speed; } else { ForwardHoldKey = movementParams.HoldKeyToApply; ForwardSpeed = movementParams.Speed; } } } else if ((motion & (uint)CommandMask.Style) != 0) { if (CurrentStyle != motion) { ForwardCommand = (uint)MotionCommand.Ready; CurrentStyle = motion; } } else if ((motion & (uint)CommandMask.Action) != 0) { AddAction(motion, movementParams.Speed, movementParams.ActionStamp, movementParams.Autonomous); } break; } }
void Start() { parentholdKey = GetComponentInParent <HoldKey> (); }
public void SetHoldKey(HoldKey holdKey) { RawMotionState.CurrentHoldKey = holdKey; }
public RawMotionState(MoveToState moveToState, BinaryReader reader) { MoveToState = moveToState; PackedFlags = reader.ReadUInt32(); // security vulnerability here: // untrusted client input sending command list length Flags = (RawMotionFlags)(PackedFlags & 0x7FF); CommandListLength = (ushort)(PackedFlags >> 11); if ((Flags & RawMotionFlags.CurrentHoldKey) != 0) { CurrentHoldKey = (HoldKey)reader.ReadUInt32(); } if ((Flags & RawMotionFlags.CurrentStyle) != 0) { CurrentStyle = (MotionStance)reader.ReadUInt32(); } if ((Flags & RawMotionFlags.ForwardCommand) != 0) { ForwardCommand = (MotionCommand)reader.ReadUInt32(); } if ((Flags & RawMotionFlags.ForwardHoldKey) != 0) { ForwardHoldKey = (HoldKey)reader.ReadUInt32(); } if ((Flags & RawMotionFlags.ForwardSpeed) != 0) { ForwardSpeed = reader.ReadSingle(); } if ((Flags & RawMotionFlags.SideStepCommand) != 0) { SidestepCommand = (MotionCommand)reader.ReadUInt32(); } if ((Flags & RawMotionFlags.SideStepHoldKey) != 0) { SidestepHoldKey = (HoldKey)reader.ReadUInt32(); } if ((Flags & RawMotionFlags.SideStepSpeed) != 0) { SidestepSpeed = reader.ReadSingle(); } if ((Flags & RawMotionFlags.TurnCommand) != 0) { TurnCommand = (MotionCommand)reader.ReadUInt32(); } if ((Flags & RawMotionFlags.TurnHoldKey) != 0) { TurnHoldKey = reader.ReadUInt32(); } if ((Flags & RawMotionFlags.TurnSpeed) != 0) { TurnSpeed = reader.ReadSingle(); } if (CommandListLength > 0) { Commands = new List <MotionItem>(); for (var i = 0; i < CommandListLength; i++) { Commands.Add(new MotionItem(moveToState.WorldObject, reader)); } } }