protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { _status.Reset(); var display = GetDisplay(variables); display?.UpdateCreature(Group, _status); if (WaitForCompletion) { while (!_status.IsFinished()) { yield return(null); } } graph.GoTo(Next, variables.This, nameof(Next)); yield break; }
protected override sealed IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is Creature creature) { if (Ability.TryGetValue(variables, this, out var ability)) { creature.Moves.Add(ability.CreateMove(creature)); } else { Debug.LogWarningFormat(this, _noAbilityWarning, Name); } } else { Debug.LogWarningFormat(this, _invalidVariablesWarning, Name); } graph.GoTo(Next, variables.This, nameof(Next)); yield break; }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { Item.TryGetValue(variables, this, out var item); Amount.TryGetValue(variables, this, out var amount); if (amount <= 0) { amount = 1; Debug.LogWarningFormat(this, _amountInvalidWarning, Name); } if (item) { Player.Instance.Trainer.Inventory.Add(item, amount); } else { Debug.LogWarningFormat(this, _itemMissingWarning, Name); } graph.GoTo(Next, variables.This, nameof(Next)); yield break; }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is Mover mover) { var path = GetPath(mover); if (path != null) { _state.Start(path, mover); if (WaitForCompletion) { if (path.RepeatCount >= 0) { while (_state.Running) { yield return(null); } } else { Debug.LogWarning(_repeatInfiniteWarning, this); } } } else { Debug.LogWarningFormat(this, _pathNotFoundWarning, Name); } } else { Debug.LogWarningFormat(this, _moverNotFoundWarning, Name); } graph.GoTo(Next, variables.This, nameof(Next)); }
protected override sealed IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is Creature creature) { var skill = creature.TakePendingSkill(); if (skill != null) { if (creature.CanLearnSkill(skill)) { yield return(creature.TeachSkill(skill, variables.Context)); } } else { Debug.LogWarningFormat(this, _noSkillWarning, Name, creature.name); } } else { Debug.LogWarningFormat(this, _invalidVariablesWarning, Name); } graph.GoTo(Next, variables.This, nameof(Next)); }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is Mover mover) { var source = mover.CurrentGridPosition; var target = GetTargetPosition(variables); _path.UsePathfinding = UsePathfinding; _path.Nodes[0].Position = Vector2Int.zero; if (UsePathfinding) { var pathfinding = WorldManager.Instance.Zones[mover.gameObject.scene.buildIndex].Pathfinding; if (pathfinding) { var path = pathfinding.GetPath(mover.MovementLayer, source, target, true); if (path.Count > 1) { target = path[path.Count - 1]; } else { graph.GoTo(Next, variables.This, nameof(Next)); yield break; } } else { Debug.LogWarningFormat(this, _noPathfindingWarning, Name); graph.GoTo(Next, variables.This, nameof(Next)); yield break; } } else { var left = target + Vector2Int.left; var right = target + Vector2Int.right; var up = target + Vector2Int.up; var down = target + Vector2Int.down; if (left == source || right == source || up == source || down == source) { graph.GoTo(Next, variables.This, nameof(Next)); yield break; } var dLeft = left - source; var dRight = right - source; var dUp = up - source; var dDown = down - source; var mLeft = Mathf.Abs(dLeft.x) + Mathf.Abs(dLeft.y); var mRight = Mathf.Abs(dRight.x) + Mathf.Abs(dRight.y); var mUp = Mathf.Abs(dUp.x) + Mathf.Abs(dUp.y); var mDown = Mathf.Abs(dDown.x) + Mathf.Abs(dDown.y); var least = Mathf.Min(mLeft, mRight, mUp, mDown); if (mLeft == least) { target = left; } else if (mRight == least) { target = right; } else if (mUp == least) { target = up; } else if (mDown == least) { target = down; } } _path.Nodes[1].Position = target; _state.Start(_path, mover); if (WaitForCompletion) { while (_state.Running) { yield return(null); } } } else { Debug.LogWarningFormat(this, _moverNotFoundWarning, Name); } graph.GoTo(Next, variables.This, nameof(Next)); }