private IEnumerator Use(InstructionStore variables, InventoryItem item) { if (Location == ItemUseLocation.World) { yield return(item.UseInWorld(variables)); } else if (Location == ItemUseLocation.Battle) { yield return(item.UseInBattle(variables)); } }
public override void GetInputs(List <VariableDefinition> inputs) { if (Creature.Generator != null) { foreach (var input in Creature.Generator.Inputs) { if (InstructionStore.IsInput(input)) { inputs.Add(input.Definition); } } } }
public override void GetOutputs(List <VariableDefinition> outputs) { if (Creature.Generator != null) { foreach (var output in Creature.Generator.Outputs) { if (InstructionStore.IsOutput(output)) { outputs.Add(output.Definition); } } } }
protected override sealed IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is Creature creature) { Initializer.Execute(this, creature); graph.GoTo(ProcessCreature, variables.This, nameof(ProcessCreature)); } else { Debug.LogWarningFormat(this, _invalidVariablesWarning, Name); yield break; } }
protected override Vector2Int GetTargetPosition(InstructionStore variables) { if (Target.GetValue(variables).TryGetObject(out Mover toward)) { return(toward.CurrentGridPosition); } else { Debug.LogWarningFormat(this, _moverNotFoundWarning, Name, Target); } return(Vector2Int.zero); }
public override void GetInputs(List <VariableDefinition> inputs) { for (var i = 0; i < Trainers.Count; i++) { var trainer = Trainers[i]; if (InstructionStore.IsInput(trainer)) { inputs.Add(VariableDefinition.Create("Trainer" + i, VariableType.Store)); } } base.GetInputs(inputs); }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is InventoryItem item) { item.Toss(item.Count); } else { Debug.LogWarningFormat(this, _itemNotFoundWarning, Name); } graph.GoTo(Next, variables.This, nameof(Next)); yield break; }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is CreatureContext creature) { var display = GetDisplay(variables); display?.SetCreature(creature); graph.GoTo(Next, variables.This, nameof(Next)); } else { Debug.LogWarningFormat(this, _invalidCreatureWarning, Name); } yield break; }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is ShopItem item) { item.Purchase(Player.Instance.Trainer.Inventory); } else { Debug.LogErrorFormat(this, _itemNotFoundWarning, Name); } graph.GoTo(Next, variables.This, nameof(Next)); yield break; }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (Creature.Species != null || Creature.Creature != null) { Give(Creature); } else { Debug.LogWarningFormat(this, _creatureNotFoundWarning, 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 target) { target.WarpToPosition(Position, Direction, Layer); } else { Debug.LogWarningFormat(this, _moverNotFoundWarning, Name); } graph.GoTo(Next, variables.This, nameof(Next)); yield break; }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is StaticCollider target) { target.UnoccupyCurrentTiles(); } else { Debug.LogWarningFormat(this, _missingColliderWarning, Name); } graph.GoTo(Next, variables.This, nameof(Next)); yield break; }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is Controller target) { target.Thaw(); } else { Debug.LogWarningFormat(this, _controllerNotFoundWarning, Name); } graph.GoTo(Next, variables.This, nameof(Next)); yield break; }
protected override IEnumerator Run(InstructionStore variables) { var trainers = new List <ITrainer>(Trainers.Count); for (var i = 0; i < Trainers.Count; i++) { var variable = Trainers[i].GetValue(variables); if (variable.Type == VariableType.Empty) { Debug.LogErrorFormat(this, _trainerMissingError, name, Trainers[i]); } else if (!variable.TryGetStore(out var store) || !(store is ITrainer trainer)) { Debug.LogErrorFormat(this, _trainerInvalidError, name, Trainers[i]); }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is Item item) { Check(graph, variables, item); } else if (variables.This is InventoryItem inventoryItem) { Check(graph, variables, inventoryItem.Item); } else { Debug.LogWarningFormat(this, _itemMissingWarning, Name); graph.GoTo(OnFalse, variables.This, nameof(OnFalse)); } yield break; }
protected override IEnumerator Run(InstructionStore variables) { if (variables.This is WorldListener listener) { switch (listener.State) { case WorldListener.VariableState.Awake: yield return(Run(variables, OnAwake, nameof(OnAwake))); yield break; case WorldListener.VariableState.Enabled: yield return(Run(variables, OnEnabled, nameof(OnEnabled))); yield break; case WorldListener.VariableState.Changed: yield return(Run(variables, OnVariableChanged, nameof(OnVariableChanged))); yield break; } } else { Debug.LogWarningFormat(this, _listenerInvalidWarning, name); } }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is Creature creature) { creature.UpdatePendingTraits(); if (creature.HasPendingSkill()) { graph.GoTo(ProcessSkill, variables.This, nameof(ProcessSkill)); } } else { Debug.LogWarningFormat(this, _invalidCreatureWarning, name); } yield break; }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is Move move) { Use(graph, variables, move); } else if (variables.This is MoveContext context) { Use(graph, variables, context.Move); } else { Debug.LogWarningFormat(this, _invalidMoveWarning, Name); graph.GoTo(OnFalse, variables.This, nameof(OnFalse)); } yield break; }
protected override IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { var display = GetDisplay(variables); if (display != null) { if (Sound.WaitForCompletion) { yield return(display.PlayAndWait(Sound, variables)); } else { display.Play(Sound, variables); } } graph.GoTo(Next, variables.This, nameof(Next)); }
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 IEnumerator Run_(InstructionGraph graph, InstructionStore variables, int iteration) { if (variables.This is InventoryItem item) { if (item.Item.Type != ItemType.Key) { graph.GoTo(OnTrue, variables.This, nameof(OnTrue)); } else { graph.GoTo(OnFalse, variables.This, nameof(OnFalse)); } } else { Debug.LogWarningFormat(this, _itemNotFoundWarning, Name); graph.GoTo(OnFalse, variables.This, nameof(OnFalse)); } 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) { if (variables.This is Creature creature) { if (creature.Trainer != null && creature.Trainer.Roster.Count > 1) { creature.Trainer.Roster.RemoveCreature(creature); graph.GoTo(ReleasedNode, variables.This, nameof(ReleasedNode)); } else { graph.GoTo(CantReleaseNode, variables.This, nameof(ReleasedNode)); } } else { Debug.LogWarningFormat(this, _missingCreatureWarning, Name); graph.GoTo(CantReleaseNode, variables.This, nameof(CantReleaseNode)); } 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 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 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)); }
protected abstract Vector2Int GetTargetPosition(InstructionStore variables);
public int MakeSelection(InstructionStore variables, List <VariableValue> values, string tag) { return(SelectFirst(values, tag)); }
public virtual IEnumerator UseInBattle(InstructionStore variables) { yield return(UseInBattleInstruction.Execute(variables.Context, variables.This)); }