public void walkForward() { Vector3 target = Vector3.forward * Random.Range(4, 7) + this.transform.position; currentAction = WalkAction.GetWalkAction(target, walkSpeed, ani); this.runAction(this.gameObject, currentAction, this); }
public override void FindNextState() { if (currentAction is WaitAction) { currentAction = new WalkAction(owner, TargetType.PLAYER); } else if (currentAction is WalkAction) { GameObject nearestPlayer = FindNearestPlayer(); if ((nearestPlayer.transform.position - owner.transform.position).sqrMagnitude <= Mathf.Pow(0.22f, 2f)) { currentAction = new AttackPrepareAction(owner, nearestPlayer, 0.4f); } } else if (currentAction is AttackPrepareAction) { if (currentAction.isOver) { AttackPrepareAction prevAction = currentAction as AttackPrepareAction; currentAction = new MeleeAttackAction(owner, prevAction.targetPosition, 1f, 2f); } } else if (currentAction is MeleeAttackAction) { if (currentAction.isOver) { owner.animator.SetTrigger("Idle"); currentAction = new WaitAction(); } } }
public bool TryGetPath(Position objectToMove, Point to, out WalkAction first, out WalkAction last, float speed) { first = null; last = null; var from = objectToMove.Value; _param.Reset(objectToMove.GridCell, to, _context.MovementGrid); var path = AStarFinder.FindPath(_param); if (path.Count < 2) { return(false); } var node = first = new WalkAction( from, path[1].ToVector2() * 32 + new Vector2(16), objectToMove, speed ); for (var i = 2; i < path.Count; i++) { var move = new WalkAction( path[i - 1].ToVector2() * 32 + new Vector2(16), path[i].ToVector2() * 32 + new Vector2(16), objectToMove, speed ); node.After = move; last = node = move; } return(true); }
void SetMoveDirection(Vector2Int direction) { CellPosition newPosition = new CellPosition(_player.position.x + direction.x, _player.position.y + direction.y); var action = new WalkAction(_player.actor, newPosition); _player.actor.SetNextAction(action); }
public void walkRight() { Vector3 target = Vector3.right * Random.Range(3, 5) + this.transform.position; currentAction = WalkAction.GetWalkAction(target, walkSpeed, ani); this.runAction(this.gameObject, currentAction, this); }
public void walkLeft() { Vector3 target = new Vector3(Random.Range(-1, 1), 0, Random.Range(-1, 1)) + transform.position; currentAction = WalkAction.GetWalkAction(target, walkSpeed, ani); this.runAction(this.gameObject, currentAction, this); }
public void walkBack() { Vector3 target = Vector3.back * Random.Range(3, 5) + this.transform.position; action = WalkAction.GetWalkAction(walkSpeed, target, animator); this.RunAction(this.gameObject, action, this); }
public void walk() { Vector3 target = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)) + transform.position; baseAction = WalkAction.GetWalkAction(target, walkSpeed, animator); this.runAction(this.gameObject, baseAction, this); }
public static WalkAction GetWalkAction(Vector3 target, float speed, Animator ani) { WalkAction currentAction = ScriptableObject.CreateInstance <WalkAction>(); currentAction.speed = speed; currentAction.target = target; currentAction.ani = ani; return(currentAction); }
public static WalkAction GetWalkAction(float speed, Vector3 des, Animator ani) { WalkAction currentAction = ScriptableObject.CreateInstance <WalkAction>(); currentAction.speed = speed; currentAction.destination = des; currentAction.animator = ani; return(currentAction); }
public Params(WalkMethod walkMethod, WalkAction walkAction, WalkParams walkParams, bool sink) { WalkMethod = walkMethod; WalkAction = walkAction; WalkParams = walkParams; Sink = sink; IsPoint = false; IsOverall = false; IsTotal = true; }
public Action GetAction(EntityMap entityMap, GroundMap groundMap) { Action action; var aStar = new AStar(groundMap, entityMap); var target = entityMap.GetPlayer(); var actionResult = new ActionResult(); if (target == null) { // If no target, the pathfinding doesn't know what to do, so wait instead and send a message up action = BuildWaitAction(actionResult, entityMap, groundMap); } // Right now enemies will only act if the player can see them else if (groundMap.isTileVisible(owner.position)) { // Attempt to move towards the AIs target (this doesn't have to be the player!) if (owner.DistanceTo(target) >= 2) { var moveTile = aStar.FindPathToTarget((owner.position.x, owner.position.y), (target.position.x, target.position.y)); if (moveTile == null) { // No path found I guess action = BuildWaitAction(actionResult, entityMap, groundMap); } else { action = new WalkAction(owner.actor, new CellPosition(moveTile.x, moveTile.y)); } } else { // If we're in melee range, attack instead of move if (owner.GetComponent <Fighter>() == null) { // Can't fight though... ha action = BuildWaitAction(actionResult, entityMap, groundMap); } else { action = new MeleeAttackAction(owner.actor, target.position); } } } else { // Nothing to do, not visible, just wait action = BuildWaitAction(actionResult, entityMap, groundMap, logMessage: false); } return(action); }
public Params(WalkMethod walkMethod, WalkAction walkAction, WalkParams walkParams, bool sink, ILocator path, IData key) { WalkMethod = walkMethod; WalkAction = walkAction; WalkParams = walkParams; Sink = sink; Path = path; FromKey = key; ToKey = key; IsPoint = true; IsOverall = false; IsTotal = false; }
public void Start() { goToPoint = transform.position; mRigidbody = GetComponent <Rigidbody>(); if (debugDst != null) { goToPosition(debugDst); } patrolAction = new PatrolAction(this, this); crowlAction = new CrowlAction(this, this); walkAction = new WalkAction(this, this); AddAction(patrolAction); // AddAction(crowlAction); base.Start(); }
protected override bool EvaluatePrecondition() { // check distance to player float distance = Vector3.Distance(needs.transform.position, myObject.transform.position); if (distance <= myObject.interactionDistance) { return(true); } // force enqueue a move action WalkAction walkAction = new WalkAction(myObject, null, null, null); needs.GetComponent <ActionManager>().ForceAction(walkAction); return(false); }
protected override bool EvaluatePrecondition() { if (!base.EvaluatePrecondition()) { return(false); } // check distance to player if (CheckDistance()) { return(true); } // force enqueue a move action WalkAction walkAction = new WalkAction(myObject, null, null, null); needs.GetComponent <ActionManager>().ForceAction(walkAction); return(false); }
public void OnKeydown(IntVector2 dir) { if (!turn) { return; } turn = false; StartCoroutine(Reset()); print(stage.actors.Count); Action next = null; if (dir.Equals(Direction.NORTH)) { next = new WalkAction(stage.hero, stage, Direction.NORTH); } else if (dir.Equals(Direction.EAST)) { next = new WalkAction(stage.hero, stage, Direction.EAST); } else if (dir.Equals(Direction.SOUTH)) { next = new WalkAction(stage.hero, stage, Direction.SOUTH); } else if (dir.Equals(Direction.WEST)) { next = new WalkAction(stage.hero, stage, Direction.WEST); } if (next != null) { stage.hero.setNextAction(next); } TUpdate(); gameBuilder.Display(); //heroTrans.transform.position = new Vector2 (stage.hero.pos.x * dungeon.tileSize.x/100,stage.hero.pos.x * dungeon.tileSize.x/100); }
public void ApplyOp(IPlayerOp op) { if (this.isDie) { return; } switch (op.Type) { case PlayerOpEnum.Move: WalkAction wa = new WalkAction(); wa.dir = (op as MoveOp).Direction; this.ApplyChangePos(wa); break; case PlayerOpEnum.Jump: JumpAction ja = new JumpAction(); this.ApplyChangePos(ja); break; } }
public void Update() { //Note: If the actor is pushed during this compound action, it will automatically warp back to the path. We should handle interruptions where the actor is attacked if (action?.Done() != false) { if (points.Count == 0) { return; } //Make a new action if (points.Count > 0) { //Truncate to integer coordinates so that we don't get confused by floats action = new WalkAction(actor, points.First.Value.i - actor.Position.i); points.RemoveFirst(); } } else { action.Update(); } }
public static void WalkJson(JObject root, string jsonPath, MissingElementHandling missingElementHandling, WalkAction action) { var path = jsonPath.Split(new char[] { '.' }); var node = root; for (int i = 0; i < path.Length - 1; ++i) { var step = path[i]; var nextNode = node[step] as JObject; if (nextNode == null) { switch (missingElementHandling) { case MissingElementHandling.Throw: throw new InvalidPropertyPathException("null", String.Join(".", path.Take(i + 1))); case MissingElementHandling.Create: nextNode = new JObject(); node[step] = nextNode; break; case MissingElementHandling.Stop: action(null, null); return; } } node = nextNode; } var lastStep = path[path.Length - 1]; action(node, lastStep); }
public Params(WalkMethod walkMethod, WalkAction walkAction, WalkParams walkParams, bool sink, Locator path, IData key) { WalkMethod = walkMethod; WalkAction = walkAction; WalkParams = walkParams; Sink = sink; Path = path; FromKey = key; ToKey = key; IsPoint = true; IsOverall = false; IsTotal = false; }
/// <summary> /// The return is to exit the Game /// </summary> /// <returns></returns> public override bool HandleInput() { var originalColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Black; var inputs = Inputs.Instance; var lastInput = GetPlayerInput(); Console.ForegroundColor = originalColor; var exitGameLoop = false; Action action = null; //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Player Actions. //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- if (lastInput == inputs.forfeit) { var dialog = new ForfeitDialog(_gameState.Game); dialog.Process(); var result = dialog.DialogResult; if (result == ForfeitDialogResult.Yes) { ScreenResult = new ScreenTransitionResult { FromScreen = ScreenType.InGame, ToScreen = ScreenType.MainMenu, Result = null }; Storage.Heroes.RemoveAll(x => x.Name == _gameState.Game.Hero.Name); Storage.Save(); exitGameLoop = true; } } // Input.forfeit, else if (lastInput == inputs.quit) { var dialog = new ConfirmDialog("Are you sure you want to quit the game?"); dialog.Process(); var result = dialog.DialogResult; if (result == ConfirmDialogResult.Yes) { ScreenResult = new ScreenTransitionResult { FromScreen = ScreenType.InGame, ToScreen = ScreenType.MainMenu, Result = null }; Storage.Update(_gameState); Storage.Save(); exitGameLoop = true; } } // Input.quit, else if (lastInput == inputs.closeDoor) { // See how many adjacent open doors there are. var doors = new List <VectorBase>(); foreach (var direction in Direction.All) { var pos = _gameState.Game.Hero.Position + direction; if (_gameState.Game.CurrentStage[pos].Type.ClosesTo != null) { doors.Add(pos); } } if (doors.Count == 0) { _gameState.Game.Log.Error("You are not next to an open door."); } else if (doors.Count == 1) { _gameState.Game.Hero.SetNextAction(new CloseDoorAction(doors[0])); } else { var closeDoorDialog = new CloseDoorDialog(_gameState.Game); closeDoorDialog.Process(); } } // Input.closeDoor, else if (lastInput == inputs.drop) { ShowItemDialog(ItemDialogUsage.Drop); } // Input.drop, else if (lastInput == inputs.use) { ShowItemDialog(ItemDialogUsage.Use); } // Input.use, else if (lastInput == inputs.pickUp) { var items = _gameState.Game.CurrentStage.itemsAt(_gameState.Game.Hero.Position); if (items.Count > 1) { // Show item dialog if there are multiple things to pick up. ShowItemDialog(ItemDialogUsage.PickUp); } else { // Otherwise attempt to pick up any available item. _gameState.Game.Hero.SetNextAction(new PickUpAction(items.Count - 1)); } } // Input.pickUp, else if (lastInput == inputs.swap) { if (_gameState.Game.Hero.Inventory.lastUnequipped == -1) { _gameState.Game.Log.Error("You aren't holding an unequipped item to swap."); } else { action = new EquipAction(ItemLocations.Inventory, _gameState.Game.Hero.Inventory.lastUnequipped); } } // Input.swap, else if (lastInput == inputs.toss) { ShowItemDialog(ItemDialogUsage.Toss); } // Input.toss, else if (lastInput == inputs.selectCommand) { var commands = _gameState.Game.Hero.HeroClass.Commands.Where(cmd => cmd.CanUse(_gameState.Game)); if (!commands.Any()) { _gameState.Game.Log.Error("You don't have any commands you can perform."); } else { Command commandToProcess = null; if (commands.Count() > 1) { var dialog = new SelectCommandDialog(_gameState.Game); dialog.Process(); commandToProcess = dialog.DialogResult; } else { commandToProcess = commands.First(); } if (commandToProcess is TargetCommand) { var targetCommand = commandToProcess as TargetCommand; // If we still have a visible target, use it. if (_gameState.Game.Target != null && _gameState.Game.Target.IsAlive && _gameState.Game.CurrentStage[_gameState.Game.Target.Position].Visible) { _gameState.Game.Hero.SetNextAction(targetCommand.GetTargetAction(_gameState.Game, _gameState.Game.Target.Position)); } else { // No current target, so ask for one. var targetDialog = new TargetDialog(targetCommand.GetRange(_gameState.Game), (target) => _gameState.Game.Hero.SetNextAction(targetCommand.GetTargetAction(_gameState.Game, target)), _gameState.Game); targetDialog.Process(); } } else if (commandToProcess is DirectionCommand) { var directionCommand = commandToProcess as DirectionCommand; var directionDialog = new DirectionDialog(directionCommand, _gameState.Game); directionDialog.Process(); } else { throw new NotImplementedException(); } } } // Input.selectCommand, else if (lastInput == inputs.stats) { ShowHeroStatisticsDialog(); } // Input.HeroStatistics, else if (lastInput.Key == ConsoleKey.Z) { ShowStorageDialog(); } // Storage else if (lastInput.Key == ConsoleKey.Oem3) { ShowConsoleDialog(); } // Storage //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Running Options //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- else if (lastInput == inputs.runNW) { _gameState.Game.Hero.Run(Direction.NorthWest); } // Input.runNW, else if (lastInput == inputs.runN) { _gameState.Game.Hero.Run(Direction.North); } // Input.runN, else if (lastInput == inputs.runNE) { _gameState.Game.Hero.Run(Direction.NorthEast); } // Input.runNE, else if (lastInput == inputs.runW) { _gameState.Game.Hero.Run(Direction.West); } // Input.runW, else if (lastInput == inputs.runE) { _gameState.Game.Hero.Run(Direction.East); } // Input.runE, SemiColon else if (lastInput == inputs.runSW) { _gameState.Game.Hero.Run(Direction.SouthWest); } // Input.runSW, else if (lastInput == inputs.runS) { _gameState.Game.Hero.Run(Direction.South); } // Input.runS, else if (lastInput == inputs.runSE) { _gameState.Game.Hero.Run(Direction.SouthEast); } // Input.runSE, Slash (FWD) //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Firing Options //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- else if (lastInput == inputs.fireNW) { FireTowards(Direction.NorthWest); } // Input.fireNW, else if (lastInput == inputs.fireN) { FireTowards(Direction.North); } // Input.fireN, else if (lastInput == inputs.fireNE) { FireTowards(Direction.NorthEast); } // Input.fireNE, else if (lastInput == inputs.fireW) { FireTowards(Direction.West); } // Input.fireW, else if (lastInput == inputs.fireE) { FireTowards(Direction.East); } // Input.fireE, else if (lastInput == inputs.fireSW) { FireTowards(Direction.SouthWest); } // Input.fireSW, else if (lastInput == inputs.fireS) { FireTowards(Direction.South); } // Input.fireS, else if (lastInput == inputs.fireSE) { FireTowards(Direction.SouthEast); } // Input.fireSE, //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // directions. //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- else if (lastInput == inputs.nw) { action = new WalkAction(Direction.NorthWest); } // Input.nw, else if (lastInput == inputs.n) { action = new WalkAction(Direction.North); } // Input.n, else if (lastInput == inputs.ne) { action = new WalkAction(Direction.NorthEast); } // Input.ne, else if (lastInput == inputs.w) { action = new WalkAction(Direction.West); } // Input.w, else if (lastInput == inputs.rest) { action = new RestAction(); } // Input.l, else if (lastInput == inputs.e) { action = new WalkAction(Direction.East); } // Input.e, else if (lastInput == inputs.sw) { action = new WalkAction(Direction.SouthWest); } // Input.sw, else if (lastInput == inputs.s) { action = new WalkAction(Direction.South); } // Input.s, else if (lastInput == inputs.se) { action = new WalkAction(Direction.SouthEast); } // Input.se, //Check if we have a non-zero value for horizontal or vertical if (action != null) { //UnityEngine.Debugger.Log("Adding action for Hero"); GameState.Instance.Game.Hero.SetNextAction(action); } return(exitGameLoop); }
private void Move(Direction d) { var action = new WalkAction(Entity, d); action.OnProcess(); }