Пример #1
0
        public override async ETTask Execute(AIComponent aiComponent, AIConfig aiConfig, ETCancellationToken cancellationToken)
        {
            Scene zoneScene = aiComponent.DomainScene();

            Unit myUnit = UnitHelper.GetMyUnitFromZoneScene(zoneScene);

            if (myUnit == null)
            {
                return;
            }

            Log.Debug("开始巡逻");

            while (true)
            {
                XunLuoPathComponent xunLuoPathComponent = myUnit.GetComponent <XunLuoPathComponent>();
                Vector3             nextTarget          = xunLuoPathComponent.GetCurrent();
                int ret = await myUnit.MoveToAsync(nextTarget, cancellationToken);

                if (ret != 0)
                {
                    return;
                }
                xunLuoPathComponent.MoveNext();
            }
        }
Пример #2
0
        public override async ETTask Execute(AIComponent aiComponent, AIConfig aiConfig, ETCancellationToken cancellationToken)
        {
            Scene zoneScene = aiComponent.DomainScene();

            Unit myUnit = UnitHelper.GetMyUnit(zoneScene);

            if (myUnit == null)
            {
                return;
            }

            // 停在当前位置
            zoneScene.GetComponent <SessionComponent>().Session.Send(new C2M_Stop());

            Log.Debug("开始攻击");

            for (int i = 0; i < 100000; ++i)
            {
                Log.Debug($"攻击: {i}次");

                // 因为协程可能被中断,任何协程都要传入cancellationToken,判断如果是中断则要返回
                bool timeRet = await TimerComponent.Instance.WaitAsync(1000, cancellationToken);

                if (!timeRet)
                {
                    return;
                }
            }
        }
Пример #3
0
        protected override async ETTask Run(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply)
        {
            Unit unit = EntityFactory.CreateWithId <Unit, int>(scene, IdGenerater.Instance.GenerateId(), 1001);

            unit.AddComponent <MoveComponent>();
            unit.Position = new Vector3(-10, 0, -10);

            NumericComponent numericComponent = unit.AddComponent <NumericComponent>();

            numericComponent.Set(NumericType.Speed, 6f);             // 速度是6米每秒

            unit.AddComponent <MailBoxComponent>();
            await unit.AddLocation();

            unit.AddComponent <UnitGateComponent, long>(request.GateSessionId);
            scene.GetComponent <UnitComponent>().Add(unit);
            response.UnitId = unit.Id;

            // 把自己广播给周围的人
            M2C_CreateUnits createUnits = new M2C_CreateUnits();

            createUnits.Units.Add(UnitHelper.CreateUnitInfo(unit));
            MessageHelper.Broadcast(unit, createUnits);

            // 把周围的人通知给自己
            createUnits.Units.Clear();
            Unit[] units = scene.GetComponent <UnitComponent>().GetAll();
            foreach (Unit u in units)
            {
                createUnits.Units.Add(UnitHelper.CreateUnitInfo(u));
            }
            MessageHelper.SendActor(unit.GetComponent <UnitGateComponent>().GateSessionActorId, createUnits);

            reply();
        }
Пример #4
0
        protected override async ETTask Run(Scene scene, M2M_UnitTransferRequest request, M2M_UnitTransferResponse response, Action reply)
        {
            await ETTask.CompletedTask;
            UnitComponent unitComponent = scene.GetComponent <UnitComponent>();
            Unit          unit          = request.Unit;

            unitComponent.AddChild(unit);
            unitComponent.Add(unit);

            foreach (Entity entity in request.Entitys)
            {
                unit.AddComponent(entity);
            }

            unit.AddComponent <MoveComponent>();
            unit.AddComponent <PathfindingComponent, string>(scene.Name);
            unit.Position = new Vector3(-10, 0, -10);

            unit.AddComponent <MailBoxComponent>();

            // 通知客户端创建My Unit
            M2C_CreateMyUnit m2CCreateUnits = new M2C_CreateMyUnit();

            m2CCreateUnits.Unit = UnitHelper.CreateUnitInfo(unit);
            MessageHelper.SendToClient(unit, m2CCreateUnits);

            // 加入aoi
            unit.AddComponent <AOIEntity, int, Vector3>(9 * 1000, unit.Position);

            response.NewInstanceId = unit.InstanceId;

            reply();
        }
Пример #5
0
        protected override async ETTask Run(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply)
        {
            UnitComponent unitComponent = scene.GetComponent <UnitComponent>();
            Unit          unit          = unitComponent.AddChildWithId <Unit, int>(IdGenerater.Instance.GenerateId(), 1001);

            unit.AddComponent <MoveComponent>();
            unit.AddComponent <PathfindingComponent, string>("solo");
            unit.Position = new Vector3(-10, 0, -10);

            NumericComponent numericComponent = unit.AddComponent <NumericComponent>();

            numericComponent.Set(NumericType.Speed, 6f);             // 速度是6米每秒
            numericComponent.Set(NumericType.AOI, 15000);            // 视野15米

            unit.AddComponent <MailBoxComponent>();
            await unit.AddLocation();

            unit.AddComponent <UnitGateComponent, long>(request.GateSessionId);
            unitComponent.Add(unit);
            // 加入aoi
            unit.AddComponent <AOIEntity, int, Vector3>(9 * 1000, unit.Position);

            M2C_CreateUnits m2CCreateUnits = new M2C_CreateUnits();

            m2CCreateUnits.Units.Add(UnitHelper.CreateUnitInfo(unit));
            MessageHelper.SendToClient(unit, m2CCreateUnits);

            response.MyId = unit.Id;

            reply();
        }
Пример #6
0
        protected override void Run(EventType.AfterCombatUnitComponentCreate args)
        {
            var self = args.CombatUnitComponent;

            if (UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene()) == self.unit)
            {
                self.AddComponent <SpellPreviewComponent>();
            }
        }
Пример #7
0
        public override void Awake(TargetSelectComponent self)
        {
            //CursorImage = GetComponent<Image>();
            self.CursorColor = Color.white;
            self.waiter      = ETTask <GameObject> .Create();

            self.Init().Coroutine();

            self.HeroObj = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene()).GetComponent <GameObjectComponent>().GameObject;
        }
        protected override async ETTask Run(Scene scene, M2M_UnitTransferRequest request, M2M_UnitTransferResponse response, Action reply)
        {
            await ETTask.CompletedTask;
            UnitComponent unitComponent = scene.GetComponent <UnitComponent>();
            Unit          unit          = request.Unit;

            unitComponent.AddChild(unit);
            unitComponent.Add(unit);

            foreach (var item in request.Map)
            {
                var    entity = request.Entitys[item.ChildIndex];
                Entity parent;
                if (item.ParentIndex == -1)                //父组件为自己
                {
                    parent = unit;
                }
                else
                {
                    parent = request.Entitys[item.ParentIndex];
                }

                if (item.IsChild == 0)
                {
                    parent.AddComponent(entity);
                }
                else
                {
                    parent.AddChild(entity);
                }
            }
            unit.AddComponent <MoveComponent>();
            unit.AddComponent <PathfindingComponent, string>(scene.Name);
            unit.Position = new Vector3(-10, 0, -10);

            unit.AddComponent <MailBoxComponent>();

            // 通知客户端创建My Unit
            M2C_CreateMyUnit m2CCreateUnits = new M2C_CreateMyUnit();

            m2CCreateUnits.Unit = UnitHelper.CreateUnitInfo(unit);

            MessageHelper.SendToClient(unit, m2CCreateUnits);

            var numericComponent = unit.GetComponent <NumericComponent>();

            // 加入aoi
            var aoiu = unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType, int>
                           (unit.Position, unit.Rotation, UnitType.Player, numericComponent.GetAsInt(NumericType.AOI));

            aoiu.AddSphereTrigger(0.5f, AOITriggerType.None, null, true);
            response.NewInstanceId = unit.InstanceId;

            reply();
        }
Пример #9
0
        public override void Awake(DirectRectSelectComponent self)
        {
            self.waiter = ETTask <GameObject> .Create();

            string path = "GameAssets/SkillPreview/Prefabs/DirectRectSelectManager.prefab";

            GameObjectPoolComponent.Instance.GetGameObjectAsync(path, (obj) =>
            {
                self.gameObject = obj;
                self.DirectObj  = obj.transform.GetChild(0).gameObject;
                self.AreaObj    = self.DirectObj.transform.GetChild(0).gameObject;
                self.waiter.SetResult(obj);
                self.waiter = null;
            }).Coroutine();
            self.HeroObj = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene()).GetComponent <GameObjectComponent>().GameObject;
        }
Пример #10
0
        public override void Awake(PointSelectComponent self)
        {
            self.waiter = ETTask <GameObject> .Create();

            string path = "GameAssets/SkillPreview/Prefabs/PointSelectManager.prefab";

            GameObjectPoolComponent.Instance.GetGameObjectAsync(path, (obj) =>
            {
                self.gameObject     = obj;
                self.RangeCircleObj = obj.transform.Find("RangeCircle").gameObject;
                self.SkillPointObj  = obj.transform.Find("SkillPointPreview").gameObject;
                self.waiter.SetResult(obj);
                self.waiter = null;
            }).Coroutine();
            self.HeroObj = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene()).GetComponent <GameObjectComponent>().GameObject;
        }