コード例 #1
0
        protected override void Run(ETModel.Session session, Actor_StateSync message)
        {
            UnitComponent unitComponent = ETModel.Game.Scene.GetComponent <UnitComponent>();

            foreach (UnitStateInfo stateInfo in message.States)
            {
                Unit unit = unitComponent.Get(stateInfo.UnitId);
                if (unit == null)
                {
                    continue;
                }

                UnitState state = stateInfo.Read();

                if (stateInfo.UnitId == PlayerComponent.Instance.MyPlayer.UnitId)
                {
                    ClientPredictionComponent clientPredictionComponent = ETModel.Game.Scene.GetComponent <ClientPredictionComponent>();
                    clientPredictionComponent.SetVerifyState(state);
                }
                else
                {
                    UnitStateComponent unitStateComponent = unit.GetComponent <UnitStateComponent>();
                    unitStateComponent.SetState(state);
                }
            }
        }
コード例 #2
0
        public static void GetInput(this UnitStateComponent unitStateComponent, int frame, ICommandInput commandInput)
        {
            try
            {
                //unitStateComponent.collectInput = true;
                //if (unitStateComponent.currGetInputFrame < frame)
                //    unitStateComponent.currGetInputFrame = frame;
                //UnitStateDelta unitStateDelta = new UnitStateDelta();
                //unitStateDelta.frame = frame;

                var result = Game.Scene.GetComponent <CommandSimulaterComponent>().commandSimulaters[commandInput.GetType()].Simulate(commandInput, unitStateComponent.unit);
                switch (result)
                {
                case CommandResult_Move result_Move:
                    unitStateComponent.unit.GetComponent <CharacterMoveComponent>().MoveAsync(result_Move.Path).Coroutine();

                    unitStateComponent.inputResult_Move.Frame    = frame;
                    unitStateComponent.inputResult_Move.Id       = unitStateComponent.unit.Id;
                    unitStateComponent.inputResult_Move.PathList = new Google.Protobuf.Collections.RepeatedField <Vector3Info>();
                    for (int i = 0; i < result_Move.Path.Count; i++)
                    {
                        unitStateComponent.inputResult_Move.PathList.Add(new Vector3Info()
                        {
                            X = result_Move.Path[i].x,
                            Y = result_Move.Path[i].y,
                            Z = result_Move.Path[i].z
                        });
                    }
                    MessageHelper.Broadcast(unitStateComponent.inputResult_Move);
                    break;

                case CommandResult_UseSkill result_UseSkill:

                    bool checkResult = unitStateComponent.unit.GetComponent <ActiveSkillComponent>().CheckCanUse(result_UseSkill.skillId);
                    if (checkResult)
                    {
                        unitStateComponent.unit.GetComponent <ActiveSkillComponent>().Execute(result_UseSkill.skillId).Coroutine();
                    }
                    switch ((commandInput as CommandInput_UseSkill).bufferValue)
                    {
                    case BufferValue_Dir bufferValue_Dir:
                        unitStateComponent.useSkill_Dir.SkillId        = result_UseSkill.skillId;
                        unitStateComponent.useSkill_Dir.Success        = checkResult;
                        unitStateComponent.useSkill_Dir.Id             = unitStateComponent.unit.Id;
                        unitStateComponent.useSkill_Dir.PipelineSignal = (commandInput as CommandInput_UseSkill).pipelineSignal;
                        unitStateComponent.useSkill_Dir.Dir            = bufferValue_Dir.dir.ToV3Info();
                        MessageHelper.Broadcast(unitStateComponent.useSkill_Dir);
                        break;
                    }
                    break;
                }
                //unitStateDelta.commandResults.Add(result.GetType(), result);
                //unitStateComponent.unitStatesDic[unitStateComponent.currGetInputFrame] = unitStateDelta;
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }
コード例 #3
0
        public static void Awake(this UnitStateComponent self)
        {
            UnitState defaultState = new UnitState();

            defaultState.Position = new Vector3(24, 0, -13);
            defaultState.Rotate   = 0;
            defaultState.Velocity = 0;
            self.State            = defaultState;
        }
コード例 #4
0
        protected override void Run(Unit unit, C2M_Input_Move message)
        {
            UnitStateComponent unitStateComponent = unit.GetComponent <UnitStateComponent>();

            CommandInput_Move commandInput_Move = new CommandInput_Move();

            commandInput_Move.clickPos = new Vector3(message.AimPos.X, message.AimPos.Y, message.AimPos.Z);
            unitStateComponent.GetInput(message.Frame, commandInput_Move);
        }
コード例 #5
0
        public static void FixedUpdate(this UnitStateComponent unitStateComponent)
        {
            if (!unitStateComponent.haveInited)
            {
                return;
            }
            if (unitStateComponent.unitStatesDic.Count == 0)
            {
                return;
            }
            UnitStateMgrComponent mgr = Game.Scene.GetComponent <UnitStateMgrComponent>();

            Log.Info(string.Format("frame {0} : 玩家位置信息 {1}", mgr.currFrame, unitStateComponent.unit.Position));
            //每间隔3帧发一次数据
            if (mgr.currFrame - unitStateComponent.preSendMsgFrame < UnitStateMgrComponent.sendMsgDelta)
            {
                return;
            }
            unitStateComponent.preSendMsgFrame = mgr.currFrame;

            if (!unitStateComponent.collectInput)
            {
                return;
            }

            //TODO : 这里有大量GC,需要处理
            //if (unitStateComponent.currGetInputFrame - unitStateComponent.preClearInputFrame >= UnitStateComponent.maxFrameCount_SaveStateDelta)
            //{
            //    for (int i = unitStateComponent.preClearInputFrame; i < unitStateComponent.currGetInputFrame - UnitStateComponent.maxFrameCount_SaveStateDelta; i++)
            //    {
            //        if (unitStateComponent.unitStatesDic.ContainsKey(i))
            //        {
            //            unitStateComponent.unitStatesDic.Remove(i);
            //        }
            //    }
            //}

            //每次发送都发最新的的结果
            //var state = unitStateComponent.unitStatesDic[unitStateComponent.currGetInputFrame];

            //foreach (var v in state.commandResults)
            //{
            //    CommandResultInfo_Move commandResultInfo_Move = new CommandResultInfo_Move();
            //    commandResultInfo_Move.Frame = state.frame;

            //    switch (v.Value)
            //    {
            //        case CommandResult_Move result_Move:

            //            continue;
            //    }
            //}
            unitStateComponent.collectInput = false;
        }
コード例 #6
0
        protected override void Run(Unit unit, C2M_Input_UseSkill_Dir message)
        {
            UnitStateComponent    unitStateComponent    = unit.GetComponent <UnitStateComponent>();
            CommandInput_UseSkill commandInput_UseSkill = CommandGCHelper.GetCommandInput <CommandInput_UseSkill>();

            commandInput_UseSkill.skillId        = message.SkillId;
            commandInput_UseSkill.pipelineSignal = message.PipelineSignal;
            commandInput_UseSkill.bufferValue    = new BufferValue_Dir()
            {
                dir = message.AimDir.ToV3()
            };

            unitStateComponent.GetInput(message.Frame, commandInput_UseSkill);
        }
コード例 #7
0
        public static void SyncStateFrame(this UnitStateComponent self, Move move)
        {
            // 获取输出数据,传入CharacterMovementComponet
            // 服务器上要有一份同样的角色移动数据,用于服务端的各种计算与判断
            CharacterMoveComponent characterMoveComponent = self.unit.GetComponent <CharacterMoveComponent>();

            characterMoveComponent.MoveAsync(move);


            // 向附近玩家广播targetMove,更新preSendMsgFrame
            if (self.preSendMsgFrame != self.currFrame)
            {
                MapHelper.BroadcastMove(characterMoveComponent.targetMove, self.unit);
                self.preSendMsgFrame = self.currFrame;
            }
        }
コード例 #8
0
        private static void ExecuteCommand(this UnitSimulateComponent self, StateCommand command)
        {
            UnitStateComponent unitStateComponent = self.Entity.GetComponent <UnitStateComponent>();
            UnitState          newState           = unitStateComponent.State;

            newState.Rotate   = self.CalculaAngle(command.input.axisX, command.input.axisY);
            newState.Velocity = VelocityConst.Accelerate;

            unitStateComponent.State = newState;

            StateResult result = new StateResult();

            result.rotate   = newState.Rotate;
            result.velocity = newState.Velocity;

            command.result = result;
            command.frame  = newState.Frame;
        }
コード例 #9
0
        private static void OnSimulateAfter(this UnitSimulateComponent self)
        {
            ActorMessageSenderComponent actorLocationSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();
            UnitGateComponent           unitGateComponent            = self.Entity.GetComponent <UnitGateComponent>();
            ActorMessageSender          actorMessageSender           = actorLocationSenderComponent.Get(unitGateComponent.GateSessionActorId);

            if (unitGateComponent.IsDisconnect)
            {
                return;
            }

            if (self.ExecuteQueue.Count > 0)
            {
                Actor_ServerCommond serverCommond = new Actor_ServerCommond();
                while (self.ExecuteQueue.Count > 0)
                {
                    StateCommand stateCommand = self.ExecuteQueue.Dequeue();
                    serverCommond.Result.Add(stateCommand.ToCommand());
                }

                actorMessageSender.Send(serverCommond);
            }

            if (self.Frame % UnitStateComponent.SyncFrame == 1)
            {
                Actor_StateSync stateSync = new Actor_StateSync();

                Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll();
                foreach (Unit unit in units)
                {
                    UnitStateComponent unitStateComponent = unit.GetComponent <UnitStateComponent>();
                    UnitState          state = unitStateComponent.State;
                    UnitStateInfo      info  = state.Pack(unit.Id, state.Frame);
                    stateSync.States.Add(info);
                }

                actorMessageSender.Send(stateSync);
            }
        }
コード例 #10
0
        protected async ETVoid RunAsync(Session session, G2M_CreateUnit message, Action <M2G_CreateUnit> reply)
        {
            M2G_CreateUnit response = new M2G_CreateUnit();

            try
            {
                UnitData playerData = new UnitData();
                if (unitIndex % 2 == 0)
                {
                    playerData.groupIndex = GroupIndex.Player;
                    playerData.layerMask  = UnitLayerMask.ALL;
                    playerData.unitLayer  = UnitLayer.Character;
                    playerData.unitTag    = UnitTag.Player;
                }
                else
                {
                    playerData.groupIndex = GroupIndex.Monster;
                    playerData.layerMask  = UnitLayerMask.ALL;
                    playerData.unitLayer  = UnitLayer.Character;
                    playerData.unitTag    = UnitTag.Monster;
                }
                unitIndex++;
                Unit unit = UnitFactory.Create(IdGenerater.GenerateId(), 1001, playerData);
                await unit.AddComponent <MailBoxComponent>().AddLocation();

                unit.AddComponent <UnitGateComponent, long>(message.GateSessionId);


                unit.Position = new Vector3(-10, 0, -10);


                UnitStateComponent stateCom = unit.GetComponent <UnitStateComponent>();

                Game.Scene.GetComponent <UnitStateMgrComponent>().Add(stateCom);

                response.UnitId = unit.Id;



                // 广播创建的unit
                M2C_CreateUnits createUnits = new M2C_CreateUnits();
                Unit[]          units       = Game.Scene.GetComponent <UnitComponent>().GetAll();
                foreach (Unit u in units)
                {
                    UnitInfo           unitInfo           = new UnitInfo();
                    UnitStateComponent unitStateComponent = u.GetComponent <UnitStateComponent>();
                    unitInfo.Position   = u.Position.ToV3Info();
                    unitInfo.Dir        = Vector3.forward.ToV3Info();
                    unitInfo.UnitId     = u.Id;
                    unitInfo.GroupIndex = (int)u.UnitData.groupIndex;
                    unitInfo.LayerMask  = (int)u.UnitData.layerMask;
                    unitInfo.UnitLayer  = (int)u.UnitData.unitLayer;
                    unitInfo.UnitTag    = (int)u.UnitData.unitTag;

                    foreach (var v in u.GetComponent <NumericComponent>().NumericDic)
                    {
                        unitInfo.UnitNumerics.Add(new UnitNumeric()
                        {
                            Type  = v.Key,
                            Value = v.Value
                        });
                    }

                    createUnits.Units.Add(unitInfo);
                }
                MessageHelper.Broadcast(createUnits);


                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #11
0
 //玩家刚开始的时候初始化所有的属性
 public static void Init(this UnitStateComponent unitStateComponent, Dictionary <Type, IProperty> unitProperty)
 {
     unitStateComponent.unitProperty    = unitProperty;
     unitStateComponent.haveInited      = true;
     unitStateComponent.preSendMsgFrame = -3;
 }
コード例 #12
0
        private static void OnSimulateInertance(this UnitSimulateComponent self)
        {
            UnitStateComponent unitStateComponent = self.Entity.GetComponent <UnitStateComponent>();

            unitStateComponent.State = unitStateComponent.State.Inertance(1);
        }