コード例 #1
0
        public void SubTick()
        {
            int subTick = this.m_level.GetLogicTime().GetTick();

            for (int i = 0; i < this.m_commandList.Size(); i++)
            {
                LogicCommand command = this.m_commandList[i];

                if (command.GetExecuteSubTick() < subTick)
                {
                    Debugger.Error(string.Format("Execute command failed! Command should have been executed already. (type={0} server_tick={1} command_tick={2})",
                                                 command.GetCommandType(),
                                                 subTick,
                                                 command.GetExecuteSubTick()));
                }

                if (command.GetExecuteSubTick() == subTick)
                {
                    if (this.IsCommandAllowedInCurrentState(command))
                    {
                        if (command.Execute(this.m_level) == 0)
                        {
                            this.m_listener?.CommandExecuted(command);
                            this.m_level.GetGameMode().GetReplay()?.RecordCommand(command);
                        }

                        this.m_commandList.Remove(i--);
                    }
                    else
                    {
                        Debugger.Error(string.Format("Execute command failed! Command not allowed in current state. (type={0} current_state={1}",
                                                     command.GetCommandType(),
                                                     this.m_level.GetState()));
                    }
                }
            }
        }
コード例 #2
0
        public void Encode(ChecksumEncoder encoder)
        {
            encoder.EnableCheckSum(false);
            encoder.WriteInt(this.m_commandList.Size());

            for (int i = 0; i < this.m_commandList.Size(); i++)
            {
                LogicCommand command = this.m_commandList[i];

                encoder.WriteInt((int)command.GetCommandType());
                command.Encode(encoder);
            }

            encoder.EnableCheckSum(true);
        }
コード例 #3
0
        public bool IsCommandAllowedInCurrentState(LogicCommand command)
        {
            int commandType = (int)command.GetCommandType();
            int state       = this.m_level.GetState();

            if (state == 4)
            {
                Debugger.Warning("Execute command failed! Commands are not allowed in visit state.");
                return(false);
            }

            if (commandType < 1000)
            {
                if (commandType < 800)
                {
                    if (commandType >= 700)
                    {
                        if (state != 2 && state != 5)
                        {
                            Debugger.Error("Execute command failed! Command is only allowed in attack state.");
                            return(false);
                        }
                    }
                    else if (commandType >= 500)
                    {
                        if (state != 1)
                        {
                            Debugger.Error("Execute command failed! Command is only allowed in home state.");
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
コード例 #4
0
 public static void SaveCommandToJSON(LogicJSONObject jsonObject, LogicCommand command)
 {
     jsonObject.Put("ct", new LogicJSONNumber((int)command.GetCommandType()));
     jsonObject.Put("c", command.GetJSONForReplay());
 }
コード例 #5
0
 public static void EncodeCommand(ChecksumEncoder encoder, LogicCommand command)
 {
     encoder.WriteInt((int)command.GetCommandType());
     command.Encode(encoder);
 }