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 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); } } }
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; } }
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); }
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; }
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); }
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; }
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); }
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; }
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(); }
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; }
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); } }
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; } }