Exemple #1
0
        public static DUnit Create(Entity domain, DUnitInfo unitInfo)
        {
            DUnit shell = DUnitFactory.Create(domain, unitInfo.UnitId);

            // 位置信息
            shell.Position = new Vector3(unitInfo.PX, unitInfo.PY, unitInfo.PZ);
            shell.Rotation = new Quaternion(unitInfo.RX, unitInfo.RY, unitInfo.RZ, unitInfo.RW);
            // 类型信息
            shell.AddComponent <UnitTypeComponent, UnitType>(UnitType.UnitShell);
            // 配置信息
            shell.AddComponent <UShellConfigComponent, int>(unitInfo.ConfigId);
            // 运算者
            shell.AddComponent <OperationerComponent, long>(unitInfo.OperationerId);
            // 阵营信息
            shell.AddComponent <CampComponent, long, CampType>(unitInfo.GamerId, (CampType)unitInfo.Camp);
            // 数值信息
            ShellHelper.InitShellNumberic(shell);

            // 触发创建完成事件
            Game.EventSystem.Publish(new AppEventType.AfterShellCreate()
            {
                Unit = shell
            }).Coroutine();

            return(shell);
        }
Exemple #2
0
        public static void Update(this DOperaComponent self)
        {
            self.InitMyGamer();

            // 拾取
            if (self.BeUpdate)
            {
                DUnit tower = OperaHelper.PickUpUnit("Tower");
                // 拾取对象
                self.SelectUnit(tower);
                // 设置之后的拾取对象
                self.SetTargetUnit(tower);
                // 刷新拾取MAP层的点
                self.UpdateClickPoint();
            }

            // 拾取状态
            if (Input.GetMouseButtonDown(0))
            {
                self.BeUpdate = true;
            }

            // 拾取状态
            if (Input.GetMouseButtonUp(0))
            {
                if (self.BeUpdate)
                {
                    // 触发操作检测事件
                    self.TrigerOperaEvent();

                    // 重置状态
                    self.ClearSelectState();
                }
            }
        }
Exemple #3
0
 public static void ExitDamageTrigger(this Skill self, DUnit unit)
 {
     if (self.DamageList.List.Contains(unit.Id))
     {
         self.DamageList.List.Remove(unit.Id);
     }
 }
Exemple #4
0
        public static void InitSkills(this SkillComponent self)
        {
            DUnit             role          = self.GetParent <DUnit>();
            UnitTypeComponent typeComponent = role.GetComponent <UnitTypeComponent>();
            JsonData          parameter     = null;

            if (typeComponent.UnitType == UnitType.UnitRole)
            {
                parameter = JsonMapper.ToObject(role.GetComponent <URoleConfigComponent>().RoleConfig.Skills);
            }
            else if (typeComponent.UnitType == UnitType.UnitTower)
            {
                parameter = JsonMapper.ToObject(role.GetComponent <UTowerConfigComponent>().TowerConfig.Skills);
            }
            else if (typeComponent.UnitType == UnitType.UnitTrap)
            {
                parameter = JsonMapper.ToObject(role.GetComponent <UTrapConfigComponent>().TrapConfig.Skills);
            }
            else
            {
                parameter = JsonMapper.ToObject(role.GetComponent <UShellConfigComponent>().ShellConfig.Skills);
            }

            JsonData skills = parameter["skills"];

            if (skills != null)
            {
                for (int i = 0; i < skills.Count; i++)
                {
                    int skillid = (int)skills[i];
                    self.AddSkill(skillid);
                }
            }
        }
Exemple #5
0
 public static void ExitMonitorTrigger(this Skill self, DUnit unit)
 {
     if (self.MonitorList.List.Contains(unit.Id))
     {
         self.MonitorList.List.Remove(unit.Id);
     }
 }
Exemple #6
0
        public static DUnit Create(Entity domain, DUnitInfo unitInfo)
        {
            DUnit tower = DUnitFactory.Create(domain, unitInfo.UnitId);

            // 位置信息
            tower.Position = new Vector3(unitInfo.PX, unitInfo.PY, unitInfo.PZ);
            tower.Rotation = new Quaternion(unitInfo.RX, unitInfo.RY, unitInfo.RZ, unitInfo.RW);
            // 类型信息
            tower.AddComponent <UnitTypeComponent, UnitType>(UnitType.UnitTower);
            // 配置信息
            tower.AddComponent <UTowerConfigComponent, int>(unitInfo.ConfigId);
            // 运算者
            tower.AddComponent <OperationerComponent, long>(unitInfo.OperationerId);
            // 阵营信息
            tower.AddComponent <CampComponent, long, CampType>(unitInfo.GamerId, (CampType)unitInfo.Camp);
            // 数值信息
            TowerHelper.InitTowerNumberic(tower);
            // 血量恢复
            NumericComponent numeric = tower.GetComponent <NumericComponent>();

            tower.AddComponent <HPRegainComponent, int>(numeric.GetAsInt(NumericType.HPRegain));

            // 触发创建完成事件
            Game.EventSystem.Publish(new AppEventType.AfterTowerCreate()
            {
                Unit = tower
            }).Coroutine();

            return(tower);
        }
Exemple #7
0
        public static async ETTask <bool> StartMoveImp(this PathComponent self, ETCancellationToken cancellationToken)
        {
            DUnit unit  = self.GetParent <DUnit>();
            float speed = unit.GetComponent <NumericComponent>().GetAsFloat(NumericType.Speed);

            for (int i = 0; i < self.Path.List.Count; ++i)
            {
                Vector3 v = self.Path.List[i];

                if (i == 0)
                {
                    float serverf = (self.ServerPos - v).magnitude;
                    if (serverf > 0.1f)
                    {
                        float clientf = (unit.Position - v).magnitude;
                        speed = clientf / serverf * speed;
                    }
                }

                unit.GetComponent <TurnComponent>().Turn(v);

                if (await unit.GetComponent <DMoveComponent>().MoveToAsync(v, speed, cancellationToken) == false)
                {
                    return(false);
                }
            }
            return(true);
        }
        public override void Update(DMoveComponent self)
        {
            if (self.Callback == null)
            {
                return;
            }

            DUnit unit    = self.GetParent <DUnit>();
            long  timeNow = TimeHelper.ClientNow();

            if (timeNow - self.StartTime >= self.needTime)
            {
                unit.Position = self.Target;

                Action <bool> callback = self.Callback;
                self.Callback = null;
                callback.Invoke(true);

                return;
            }

            float amount = (timeNow - self.StartTime) * 1f / self.needTime;

            unit.Position = Vector3.Lerp(self.StartPos, self.Target, amount);
        }
Exemple #9
0
        public static DUnit Create(Entity domain, DUnitInfo unitInfo)
        {
            DUnit trap = DUnitFactory.Create(domain, unitInfo.UnitId);

            // 位置信息
            trap.Position = new Vector3(unitInfo.PX, unitInfo.PY, unitInfo.PZ);
            trap.Rotation = new Quaternion(unitInfo.RX, unitInfo.RY, unitInfo.RZ, unitInfo.RW);
            // 类型信息
            trap.AddComponent <UnitTypeComponent, UnitType>(UnitType.UnitTrap);
            // 配置信息
            trap.AddComponent <UTrapConfigComponent, int>(unitInfo.ConfigId);
            // 运算者
            trap.AddComponent <OperationerComponent, long>(unitInfo.OperationerId);
            // 阵营信息
            trap.AddComponent <CampComponent, long, CampType>(unitInfo.GamerId, (CampType)unitInfo.Camp);
            // 旋转组件
            trap.AddComponent <TurnComponent>();
            // 数值信息
            TrapHelper.InitTrapNumberic(trap);

            // 触发创建完成事件
            Game.EventSystem.Publish(new AppEventType.AfterTrapCreate()
            {
                Unit = trap
            }).Coroutine();

            return(trap);
        }
Exemple #10
0
        public static DUnit Create(Entity domain, DUnitInfo unitInfo)
        {
            DUnit role = DUnitFactory.Create(domain, unitInfo.UnitId);

            // 位置信息
            role.Position = new Vector3(unitInfo.PX, unitInfo.PY, unitInfo.PZ);
            role.Rotation = new Quaternion(unitInfo.RX, unitInfo.RY, unitInfo.RZ, unitInfo.RW);
            // 类型信息
            role.AddComponent <UnitTypeComponent, UnitType>(UnitType.UnitRole);
            // 配置信息
            role.AddComponent <URoleConfigComponent, int>(unitInfo.ConfigId);
            // 运算者
            role.AddComponent <OperationerComponent, long>(unitInfo.OperationerId);
            // 阵营信息
            role.AddComponent <CampComponent, long, CampType>(unitInfo.GamerId, (CampType)unitInfo.Camp);
            // 移动组件
            role.AddComponent <DMoveComponent>();
            // 旋转组件
            role.AddComponent <TurnComponent>();
            // 寻路组件
            role.AddComponent <PathComponent>();
            // 数值信息
            RoleHelper.InitRoleNumberic(role);
            // 技能组件
            role.AddComponent <SkillComponent>();

            // 触发创建完成事件
            Game.EventSystem.Publish(new AppEventType.AfterRoleCreate()
            {
                Unit = role
            }).Coroutine();

            return(role);
        }
        private async ETTask CreateShellViewAsync(DUnit shell)
        {
            UShellConfig config = shell.GetComponent <UShellConfigComponent>().ShellConfig;

            GameObject go = shell.AddComponent <DGameObjectComponent>().Init("Shell.unity3d", "Shell", config.Model, GlobalComponent.Instance.Unit);

            go.AddComponent <ComponentView>().Component = shell;
            go.transform.position = shell.Position;

            await ETTask.CompletedTask;
        }
Exemple #12
0
        public static async ETTask <bool> MoveToAsync(this DMoveComponent self, Vector3 target, float speedValue, ETCancellationToken cancellationToken = null)
        {
            await ETTask.CompletedTask;

            DUnit unit = self.GetParent <DUnit>();

            if ((target - self.Target).magnitude < 0.1f)
            {
                return(true);
            }

            self.Target = target;


            self.StartPos  = unit.Position;
            self.StartTime = TimeHelper.ClientNow();
            float distance = (self.Target - self.StartPos).magnitude;

            if (Math.Abs(distance) < 0.1f)
            {
                return(true);
            }

            self.needTime = (long)(distance / speedValue * 1000);

            ETTask <bool> moveTcs = ETTask <bool> .Create();

            self.Callback = (ret) => { moveTcs.SetResult(ret); };

            void CancelAction()
            {
                if (self.Callback != null)
                {
                    Action <bool> callback = self.Callback;
                    self.Callback = null;
                    callback.Invoke(false);
                }
            }

            bool moveRet;

            try
            {
                cancellationToken?.Add(CancelAction);
                moveRet = await moveTcs;
            }
            finally
            {
                cancellationToken?.Remove(CancelAction);
            }

            return(moveRet);
        }
        protected async ETTask CreateTrapViewAsync(DUnit trap)
        {
            URoleConfig config = trap.GetComponent <URoleConfigComponent>().RoleConfig;

            GameObject go = trap.AddComponent <DGameObjectComponent>().Init("Trap.unity3d", "Trap", config.Model, GlobalComponent.Instance.Unit);

            go.AddComponent <ComponentView>().Component = trap;
            go.transform.position = trap.Position;

            trap.AddComponent <DAnimatorComponent>();

            await ETTask.CompletedTask;
        }
Exemple #14
0
        private async ETTask CreateTowerViewAsync(DUnit role)
        {
            UTowerConfig config = role.GetComponent <UTowerConfigComponent>().TowerConfig;

            GameObject go = role.AddComponent <DGameObjectComponent>().Init("Tower.unity3d", "Tower", config.Model, GlobalComponent.Instance.Unit);

            go.AddComponent <ComponentView>().Component = role;
            go.transform.position = role.Position;

            // 声音组件
            role.AddComponent <SoundComponent>();

            await ETTask.CompletedTask;
        }
Exemple #15
0
        public static void UpdateTriggers(this Skill self)
        {
            ListComponent <long> deleteList = ListComponent <long> .Create();

            DUnitComponent dUnitComponent = self.Domain.GetComponent <DUnitComponent>();

            // 刷新MonitorList
            for (int i = 0; i < self.MonitorList.List.Count; i++)
            {
                DUnit unit = dUnitComponent.Get(self.MonitorList.List[i]);
                if (unit == null)
                {
                    deleteList.List.Add(unit.Id);
                    continue;
                }

                if (unit.GetComponent <UnitStateComponent>().UnitState == (int)UnitState.Death)
                {
                    deleteList.List.Add(unit.Id);
                }
            }
            for (int i = 0; i < deleteList.List.Count; i++)
            {
                self.MonitorList.List.Remove(deleteList.List[i]);
            }
            deleteList.List.Clear();


            // 刷新MonitorList
            for (int i = 0; i < self.DamageList.List.Count; i++)
            {
                DUnit unit = dUnitComponent.Get(self.DamageList.List[i]);
                if (unit == null)
                {
                    deleteList.List.Add(unit.Id);
                    continue;
                }

                if (unit.GetComponent <UnitStateComponent>().UnitState == (int)UnitState.Death)
                {
                    deleteList.List.Add(unit.Id);
                }
            }
            for (int i = 0; i < deleteList.List.Count; i++)
            {
                self.DamageList.List.Remove(deleteList.List[i]);
            }
            deleteList.List.Clear();
        }
Exemple #16
0
        public static async ETTask<int> MoveActionImpAsync(DUnit unit, Vector3[] paths, Vector3 serverpos, ETCancellationToken cancellationToken = null)
        {
            PathComponent pathComponent = unit.GetComponent<PathComponent>();
            if (await pathComponent.StartMove(paths, serverpos, cancellationToken))
            {
                ObjectWait objectWait = unit.GetComponent<ObjectWait>();
                objectWait.Notify(new WaitType.Wait_UnitStop() { Error = WaitTypeError.Success });

                return WaitTypeError.Success;
            }
            else
            {
                return WaitTypeError.Cancel;
            }
        }
        protected override async ETVoid Run(Session session, M2C_DPathfindingResult message)
        {
            DUnit unit = session.Domain.GetComponent <DUnitComponent>().Get(message.Id);

            Vector3 servierpos = new Vector3(message.X, message.Y, message.Z);

            using var list = ListComponent <Vector3> .Create();

            for (int i = 0; i < message.Xs.Count; ++i)
            {
                list.List.Add(new Vector3(message.Xs[i], message.Ys[i], message.Zs[i]));
            }

            await DMoveAction.MoveActionImpAsync(unit, list.List.ToArray(), servierpos);
        }
Exemple #18
0
        public static void UpdateTarget(this Skill self)
        {
            if (self.TargetId == 0)
            {
                return;
            }

            DUnitComponent dUnitComponent = self.Domain.GetComponent <DUnitComponent>();
            DUnit          unit           = dUnitComponent.Get(self.TargetId);

            if (unit == null)
            {
                self.SetSkillTarget(0);
                return;
            }
        }
Exemple #19
0
        public static void SetTargetUnit(this DOperaComponent self, DUnit unit)
        {
            // 拾取对象为空,则TargetUnit标记为空
            if (unit == null)
            {
                self.TargetTower = null;
                return;
            }

            // 只可以拾取城堡类型的对象
            if (unit.GetComponent <UnitTypeComponent>().UnitType != UnitType.UnitTower)
            {
                self.TargetTower = null;
                return;
            }

            self.TargetTower = unit;
        }
Exemple #20
0
        public static void SelectUnit(this DOperaComponent self, DUnit unit)
        {
            // 如果拾取对象为空,直接返回
            if (unit == null)
            {
                return;
            }

            // 只可以拾取城堡类型的对象
            if (unit.GetComponent <UnitTypeComponent>().UnitType != UnitType.UnitTower)
            {
                return;
            }

            CampComponent camp = unit.GetComponent <CampComponent>();

            // 只有玩家自己控制的unit才可以被选中
            if (camp.CtrlGamerId != self.MyGamer.Id)
            {
                return;
            }

            // 设置当前操作的主动阵营
            if (self.SelectedTowers.Count == 0)
            {
                self.OperaCampType = camp.Camp;
            }

            // 当前操作主动阵营的,可以加入到拾取列表
            if (self.OperaCampType != camp.Camp)
            {
                return;
            }

            // 之前没有被拾取过,可以加入到拾取列表
            if (self.SelectedTowers.Contains(unit))
            {
                return;
            }
            self.SelectedTowers.Add(unit);
        }
Exemple #21
0
        public static async ETTask<int> MoveActionAsync(DUnit unit, Vector3 targetPos, ETCancellationToken cancellationToken = null)
        {
            NavMeshPath meshPath = new NavMeshPath();

            NavMesh.CalculatePath(unit.Position, targetPos, 1, meshPath);

            if (unit.DomainScene().GetComponent<PVPComponent>().bePVP)
            {
                if (OperationerComponentSystem.IsOperationer(unit) == false)
                {
                    return WaitTypeError.Success;
                }

                // PVP 发送移动消息,封包发送
                C2M_DPathfindingResult msg = new C2M_DPathfindingResult();
                msg.Id = unit.Id;
                msg.X = unit.Position.x;
                msg.Y = unit.Position.y;
                msg.Z = unit.Position.z;
                for (int i = 0; i < meshPath.corners.Length; i++)
                {
                    msg.Xs.Add(meshPath.corners[i].x);
                    msg.Ys.Add(meshPath.corners[i].y);
                    msg.Zs.Add(meshPath.corners[i].z);
                }
                
                unit.Domain.GetComponent<SessionComponent>().Session.Send(msg);

                ObjectWait objectWait = unit.GetComponent<ObjectWait>();
                objectWait.Notify(new WaitType.Wait_UnitStop() { Error = WaitTypeError.Cancel });

                WaitType.Wait_UnitStop waitUnitStop = await objectWait.Wait<WaitType.Wait_UnitStop>(cancellationToken);
                
                return waitUnitStop.Error;
            }
            else
            {
                return await DMoveAction.MoveActionImpAsync(unit, meshPath.corners, unit.Position, cancellationToken);
            }
        }
Exemple #22
0
        public static void EnterDamageTrigger(this Skill self, DUnit unit)
        {
            // 如果符合阵营条件
            if (!SkillTargetHelper.IsTargetCamp(self.TargetCamp, self.Self.GetComponent <CampComponent>().Camp, unit.GetComponent <CampComponent>().Camp))
            {
                return;
            }

            // 如果符合类型条件
            UnitTypeComponent typeComponent = unit.GetComponent <UnitTypeComponent>();

            if (typeComponent.UnitType == UnitType.UnitRole)
            {
                URoleConfigComponent uRoleConfig = unit.GetComponent <URoleConfigComponent>();
                if (!SkillTargetHelper.IsTargetType(self.TargetType, uRoleConfig.RoleType))
                {
                    return;
                }
            }

            self.DamageList.List.Add(unit.Id);
        }
Exemple #23
0
        public static DUnit GetMonitorTarget(this Skill self, SkillTargetCondition condition)
        {
            self.UpdateTriggers();

            DUnitComponent dUnitComponent = self.Domain.GetComponent <DUnitComponent>();

            if (condition == SkillTargetCondition.MaxDistance)
            {
                Vector3 srcpos  = self.Self.Position;
                float   sqrdis  = 0;
                DUnit   selunit = null;
                for (int i = 0; i < self.MonitorList.List.Count; i++)
                {
                    DUnit u      = dUnitComponent.Get(self.MonitorList.List[i]);
                    float tmpdis = (u.Position - srcpos).sqrMagnitude;
                    if (tmpdis > sqrdis)
                    {
                        selunit = u;
                    }
                }
                return(selunit);
            }
            else
            {
                Vector3 srcpos  = self.Self.Position;
                float   sqrdis  = float.MaxValue;
                DUnit   selunit = null;
                for (int i = 0; i < self.MonitorList.List.Count; i++)
                {
                    DUnit u      = dUnitComponent.Get(self.MonitorList.List[i]);
                    float tmpdis = (u.Position - srcpos).sqrMagnitude;
                    if (tmpdis < sqrdis)
                    {
                        selunit = u;
                    }
                }
                return(selunit);
            }
        }
Exemple #24
0
        public static DUnit PickUpUnit(string layer)
        {
            int layerMask = LayerMask.GetMask(layer);

            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 1000, layerMask))
            {
                ComponentView unitview = hit.collider.gameObject.GetComponent <ComponentView>();
                if (unitview == null)
                {
                    unitview = hit.transform.parent.gameObject.GetComponent <ComponentView>();
                }

                if (unitview != null)
                {
                    DUnit unit = unitview.Component as DUnit;
                    return(unit);
                }
            }

            return(null);
        }
        public override void Update(HPRegainComponent self)
        {
            if (self.BeStart)
            {
                // 按秒恢复
                long disTime = TimeHelper.ClientNow() - self.StartMilliseconds;
                if (disTime > 1000)
                {
                    DUnit            tower = self.GetParent <DUnit>();
                    NumericComponent nm    = tower.GetComponent <NumericComponent>();
                    int hpMax = nm.GetAsInt(NumericType.MaxHp);
                    int hp    = nm.GetAsInt(NumericType.Hp);
                    // 到最大值,不再恢复
                    if (hp >= hpMax)
                    {
                        return;
                    }

                    // 确认恢复值
                    int hpRegain = ((int)disTime / 1000) * self.HpRegain;
                    if (hp + hpRegain > hpMax)
                    {
                        hpRegain = hpMax - hp;
                    }

                    // 设置增量值
                    int hpAdd = nm.GetAsInt(NumericType.HpAdd) + hpRegain;
                    NumericAction.SetUnitNumericAction(tower, NumericType.HpAdd, hpAdd);

                    // 矫正剩余时间
                    int extTime = (int)disTime % 1000;
                    self.StartMilliseconds = TimeHelper.ClientNow() - extTime;
                }
                return;
            }
        }
Exemple #26
0
 public static void Add(this DUnitComponent self, DUnit unit)
 {
     self.idUnits.Add(unit.Id, unit);
     unit.Parent = self;
 }