public void RequestStateChange(AIState requestedState, TargetData targetData = default)
 {
     requestedAIState           = requestedState;
     requestedAIStateTargetData = targetData;
 }
 public void CompleteStateChange()
 {
     requestedAIState           = AIState.None;
     requestedAIStateTargetData = default;
 }
Esempio n. 3
0
        public override void UpdateSystem()
        {
            Dependency = JobHandle.CombineDependencies(Dependency, m_raycastSystem.RaycastSystemDependency);

            if (m_inputManager.InputData.mouseInput.rightClickPressed)
            {
                NativeArray <RaycastResult> raycastResult = m_raycastSystem.RaycastResult;
                bool shiftPressed = m_inputManager.InputData.keyboardInput.shiftDown;

                Dependency = Entities.WithReadOnly(raycastResult).WithAll <SelectedTag>().ForEach((Entity entity, int entityInQueryIndex, ref CurrentTarget currentTarget, ref DynamicBuffer <Command> commandBuffer) =>
                {
                    if (raycastResult[0].raycastTargetType == RaycastTargetType.Ground)
                    {
                        TargetData targetData = new TargetData
                        {
                            targetEntity = raycastResult[0].raycastTargetEntity,
                            targetType   = AITargetType.Ground,
                            targetPos    = raycastResult[0].hitPosition
                        };

                        if (shiftPressed)
                        {
                            CommandProcessSystem.QueueCommand(CommandType.Move, commandBuffer, targetData, false);
                        }
                        else
                        {
                            commandBuffer.Clear();
                            CommandProcessSystem.QueueCommand(CommandType.Move, commandBuffer, targetData, true);
                        }

                        return;
                    }

                    Translation targetPos = GetComponent <Translation>(raycastResult[0].raycastTargetEntity);
                    TargetableByAI target = GetComponent <TargetableByAI>(raycastResult[0].raycastTargetEntity);

                    if (raycastResult[0].raycastTargetType == RaycastTargetType.ResourceNode)
                    {
                        TargetData targetData = new TargetData
                        {
                            targetEntity = raycastResult[0].raycastTargetEntity,
                            targetType   = target.targetType,
                            targetPos    = targetPos.Value
                        };

                        if (shiftPressed)
                        {
                            CommandProcessSystem.QueueCommand(CommandType.Harvest, commandBuffer, targetData, false);
                        }
                        else
                        {
                            commandBuffer.Clear();
                            CommandProcessSystem.QueueCommand(CommandType.Harvest, commandBuffer, targetData, true);
                        }
                        return;
                    }

                    if (raycastResult[0].raycastTargetType == RaycastTargetType.Enemy)
                    {
                        TargetData targetData = new TargetData
                        {
                            targetEntity = raycastResult[0].raycastTargetEntity,
                            targetType   = target.targetType,
                            targetPos    = targetPos.Value
                        };

                        if (shiftPressed)
                        {
                            CommandProcessSystem.QueueCommand(CommandType.Attack, commandBuffer, targetData, false);
                        }
                        else
                        {
                            commandBuffer.Clear();
                            CommandProcessSystem.QueueCommand(CommandType.Attack, commandBuffer, targetData, true);
                        }

                        return;
                    }
                }).ScheduleParallel(Dependency);
            }
        }