private void ExecuteOrder(IntelligenceComponent intelligence, IntelligenceOrder order, IntelligenceNode node) { InputComponent input = null; if (intelligence.Bindings.TryGetValue(typeof(InputComponent), out var binding)) { input = binding as InputComponent; } if (input.Blocked) { return; } intelligence.State = order.Type; if (order.Type == OrderType.AttackPrimary || order.Type == OrderType.AttackSecondary) { input.CursorPoint = node.Pos; intelligence.TargetPos = node.Pos; if (order.Type == OrderType.AttackPrimary) { input.PrimaryAttack = true; } if (order.Type == OrderType.AttackSecondary) { input.SecondaryAttack = true; } } if (order.Type == OrderType.Follow || order.Type == OrderType.Move) { input.MovementDirection = VectorDirection(intelligence.Pos, node.Pos); if (order.Type == OrderType.Follow) { intelligence.TargetPos = node.Pos; } if (order.Type == OrderType.Move) { intelligence.TargetPos = new Vector2Ref(node.Pos); } } intelligence.UpdateCooldownMilliseconds = order.UpdateCooldownMilliseconds; }
private void ResetInputs(IntelligenceComponent intelligence) { intelligence.TargetPos = null; intelligence.State = OrderType.Null; InputComponent input = null; if (intelligence.Bindings.TryGetValue(typeof(InputComponent), out var binding)) { input = binding as InputComponent; } input.MovementDirection.X = 0; input.MovementDirection.Y = 0; input.PrimaryAttack = false; input.SecondaryAttack = false; input.SwitchWeapons = false; input.Action = false; input.Blink = false; }
private void ResetOrderInputs(IntelligenceComponent intelligence, IntelligenceOrder order) { InputComponent input = null; if (intelligence.Bindings.TryGetValue(typeof(InputComponent), out var binding)) { input = binding as InputComponent; } if (order.Type == OrderType.AttackPrimary) { input.PrimaryAttack = false; } if (order.Type == OrderType.AttackSecondary) { input.SecondaryAttack = false; } if (order.Type == OrderType.Follow || order.Type == OrderType.Move) { input.MovementDirection = Vector2.Zero; } }
private void ProcessOrders(IntelligenceComponent intelligence) { bool orderExecuted = false; foreach (var order in intelligence.Orders) { if (orderExecuted && order.Reset) { ResetOrderInputs(intelligence, order); continue; } foreach (var node in _nodes) { if (node.Inactive) { continue; } if (order.Target == node.Type && Vector2.Distance(intelligence.Pos, node.Pos) <= order.Range) { ExecuteOrder(intelligence, order, node); orderExecuted = true; break; } } if (!orderExecuted && order.Reset) { ResetOrderInputs(intelligence, order); } } if (!orderExecuted) { ResetInputs(intelligence); } }