예제 #1
0
 public UnitCommand()
 {
     _eCommandID = EUnitCommand.UNITCMD_INVALID;
 }
예제 #2
0
 public UnitCommand(EUnitCommand eCommandID)
 {
     _eCommandID = eCommandID;
 }
예제 #3
0
파일: Brain.cs 프로젝트: xiankang/OpenWorld
    private bool ProcessCommand(UnitCommand cmd)
    {
        if (!GetReady())
        {
            return(false);
        }

        EUnitCommand eCmd = cmd._eCommandID;

        if (eCmd == EUnitCommand.UNITCMD_MOVE)
        {
            if (!_unit._isMobile)
            {
                return(false);
            }
        }
        else if (eCmd == EUnitCommand.UNITCMD_ATTACK)
        {
            if (!_unit._canAttack)
            {
                return(false);
            }
        }

        Behavior behavior = null;

        if (cmd._yQueue == QueueType.QUEUE_NONE)
        {
            //
            ClearBrainQueue();
        }
        else
        {
            if (_behaviors.Count > 0)
            {
                behavior = _behaviors.Peek();

                if (behavior.GetDefault())
                {
                }
                else
                {
                    bool popFront = true;
                    if (eCmd == EUnitCommand.UNITCMD_TOOL)
                    {
                        GameObject obj = GameEntity.GetEntity(cmd._param);
                        if (obj != null)
                        {
                            Tool tool = obj.GetComponent <Tool>();
                            if (tool != null)
                            {
                                popFront = !tool.NonInterrupting;
                            }
                        }
                    }

                    if (popFront)
                    {
                        behavior.EndBehavior();
                        _behaviors.Dequeue();
                    }
                }
            }
        }

        switch (eCmd)
        {
        case EUnitCommand.UNITCMD_MOVE:
            behavior = new BMove(this, _unit);
            break;

        case EUnitCommand.UNITCMD_ATTACK:
            behavior = new BAttack(this, _unit);
            break;

        case EUnitCommand.UNITCMD_TOOL:
            behavior = new BTool(this, _unit, cmd._param);
            break;

        default:
            Debug.LogWarning("Brain ProcessCommand: Unrecognized Unit Command");
            break;
        }

        if (behavior != null)
        {
            behavior.SetDir(cmd._v3Dir);
            behavior.SetIssuedClientNumber(cmd._clientNumber);
            behavior.SetDefault(cmd._default);
            behavior.SetLevel(cmd._level);

            if (cmd._forced)
            {
                behavior.SetForced(true);
                behavior.SetForcedTime(Game._instance.GetGameTime() + cmd._forcedDuration);
            }
            if (cmd._restricted)
            {
                behavior.SetRestricted(true);
            }
            if (cmd._duration != uint.MaxValue)
            {
                behavior.SetEndTime(Game._instance.GetGameTime() + cmd._duration);
            }
            else
            {
                behavior.SetEndTime(uint.MaxValue);
            }

            if (cmd._yQueue == QueueType.QUEUE_FRONT)
            {
                if (_behaviors.Count > 0)
                {
                    Behavior front = _behaviors.Peek();
                    if (front != null && front.GetRestricted())
                    {
                        bool popFront = true;
                        if (eCmd == EUnitCommand.UNITCMD_TOOL)
                        {
                            GameObject obj = GameEntity.GetEntity(cmd._param);
                            if (obj != null)
                            {
                                Tool tool = obj.GetComponent <Tool>();
                                if (tool != null)
                                {
                                    popFront = !tool.NonInterrupting;
                                }
                            }
                        }

                        if (popFront)
                        {
                            front.EndBehavior();
                            _behaviors.Dequeue();
                        }
                    }
                }
                _behaviors.PushFront(behavior);
            }
            else if (cmd._yQueue == QueueType.QUEUE_FRONT_CLEAR_MOVES)
            {
                foreach (Behavior temp in _behaviors)
                {
                    if (temp == null)
                    {
                        continue;
                    }

                    if (temp.GetBType() == Behavior.EBehaviorType.EBT_MOVE)
                    {
                        _behaviors.Erase(temp);
                        continue;
                    }
                }
                _behaviors.PushFront(behavior);
            }
            else
            {
                _behaviors.Enqueue(behavior);
            }

            return(true);
        }
        return(false);
    }