public static Unit Create(Scene scene, long id, UnitType unitType) { UnitComponent unitComponent = scene.GetComponent <UnitComponent>(); switch (unitType) { case UnitType.Player: { Unit unit = unitComponent.AddChildWithId <Unit, int>(id, 1001); unit.AddComponent <MoveComponent>(); unit.Position = new Vector3(-10, 0, -10); NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); numericComponent.Set(NumericType.Speed, 6f); // 速度是6米每秒 numericComponent.Set(NumericType.AOI, 15000); // 视野15米 unitComponent.Add(unit); // 加入aoi unit.AddComponent <AOIEntity, int, Vector3>(9 * 1000, unit.Position); return(unit); } default: throw new Exception($"not such unit type: {unitType}"); } }
public static void InitTrapNumberic(DUnit trap) { NumericComponent numeric = trap.AddComponent <NumericComponent>(); UTrapConfig config = trap.GetComponent <UTrapConfigComponent>().TrapConfig; // 攻速 numeric.Set(NumericType.AttackSpeedBase, config.AttackSpeed); // 攻击力 numeric.Set(NumericType.HPDamageBase, config.HPDamage); }
public static void InitTowerNumberic(DUnit tower) { NumericComponent numeric = tower.AddComponent <NumericComponent>(); UTowerConfig config = tower.GetComponent <UTowerConfigComponent>().TowerConfig; // 最大血量 numeric.Set(NumericType.MaxHpBase, config.MaxHP); // 血量 numeric.Set(NumericType.HpBase, config.HP); // 攻速 numeric.Set(NumericType.AttackSpeedBase, config.AttackSpeed); // 血量恢复 numeric.Set(NumericType.HPRegainBase, config.HPRegain); // 攻击力 numeric.Set(NumericType.HPDamageBase, config.HPDamage); }
public static void GiveNumeric(NumericType numericType, float value) { Unit mUnit = UnitComponent.Instance.MyUnit; NumericComponent numericComponent = mUnit.GetComponent <NumericComponent>(); numericComponent.Set(numericType, numericComponent.GetAsFloat(numericType) + value); }
public static void InitShellNumberic(DUnit shell) { NumericComponent numeric = shell.AddComponent <NumericComponent>(); UShellConfig config = shell.GetComponent <UShellConfigComponent>().ShellConfig; // 速度 numeric.Set(NumericType.SpeedBase, config.MoveSpeed); }
public static void PlayerNumericInit(this NumericComponent self) { ///20190621 // 这里初始化base值,给各个数值进行赋值 // 注意,这两个语句都将触发数值改变组件,只是没有写Max的处理函数,所以会没有反应 self.Set(NumericType.Max, 9981150082); //self.Set(NumericType.ManageBase, 10); //self.Set(NumericType.MaxManageBase, 100); self.Set(NumericType.ValuationBase, 12); self.Set(NumericType.MaxValuationBase, 120); //self.Set(NumericType.MeasureBase, 10); //self.Set(NumericType.MaxMeasureBase, 100); self.Set(NumericType.CaseBase, 14); self.Set(NumericType.MaxCaseBase, 140); self.Set(NumericType.LevelBase, 1); self.Set(NumericType.ExpBase, 1); self.Set(NumericType.CoinBase, 1); self.Set(NumericType.ValuationAdd, 260); // HpAdd 数值,进行赋值 self.Set(NumericType.MaxValuationAdd, 260); // MaxHpAdd 数值,进行赋值 }
public static void GiveExp(Unit unit, int num, out float preProgress, out float currProgress, out bool lvUp) { NumericComponent numericComponent = unit.GetComponent <NumericComponent>(); if (numericComponent.GetAsInt(NumericType.Level) == numericComponent.GetAsInt(NumericType.LevelMax)) { preProgress = 1; currProgress = 1; lvUp = false; return; } Debug.LogFormat("单位{0}获得经验 {1}", unit.Id, num); int expMax = numericComponent.GetAsInt(NumericType.ExpMax); int preExp = numericComponent.GetAsInt(NumericType.Exp); preProgress = preExp / ((float)expMax); int currExp = preExp + num; lvUp = false; if (currExp >= expMax) { numericComponent.Set(NumericType.Level, numericComponent.GetAsInt(NumericType.Level) + 1); lvUp = true; Game.EventSystem.Run(EventIdType.UnitLvUp, unit.Id, numericComponent.GetAsInt(NumericType.Level)); if (numericComponent.GetAsInt(NumericType.Level) == numericComponent.GetAsInt(NumericType.LevelMax)) { currProgress = 1; return; } currExp -= expMax; ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>(); //ExpForLevelUp expConfig = configComponent.Get(typeof(ExpForLevelUp), numericComponent.GetAsInt(NumericType.等级)) as ExpForLevelUp; //expMax = expConfig.Exp; //numericComponent.Set(NumericType.经验Max, expMax); } currProgress = Mathf.Clamp01(currExp / ((float)expMax)); numericComponent.Set(NumericType.Exp, currExp); }
public static Unit Create(Scene currentScene, UnitInfo unitInfo) { UnitComponent unitComponent = currentScene.GetComponent <UnitComponent>(); Unit unit = unitComponent.AddChildWithId <Unit, int>(unitInfo.UnitId, unitInfo.ConfigId); unitComponent.Add(unit); unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); unit.Forward = new Vector3(unitInfo.ForwardX, unitInfo.ForwardY, unitInfo.ForwardZ); NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); for (int i = 0; i < unitInfo.Ks.Count; ++i) { numericComponent.Set(unitInfo.Ks[i], unitInfo.Vs[i]); } unit.AddComponent <MoveComponent>(); if (unitInfo.MoveInfo != null) { if (unitInfo.MoveInfo.X.Count > 0) { using (ListComponent <Vector3> list = ListComponent <Vector3> .Create()) { list.Add(unit.Position); for (int i = 0; i < unitInfo.MoveInfo.X.Count; ++i) { list.Add(new Vector3(unitInfo.MoveInfo.X[i], unitInfo.MoveInfo.Y[i], unitInfo.MoveInfo.Z[i])); } unit.MoveToAsync(list).Coroutine(); } } } unit.AddComponent <ObjectWait>(); unit.AddComponent <XunLuoPathComponent>(); Game.EventSystem.Publish(unit.DomainScene(), new EventType.AfterUnitCreate() { Unit = unit }); return(unit); }
public static void InitRoleNumberic(DUnit role) { NumericComponent numeric = role.AddComponent <NumericComponent>(); URoleConfig config = role.GetComponent <URoleConfigComponent>().RoleConfig; // 最大血量 numeric.Set(NumericType.MaxHpBase, config.HP); // 血量 numeric.Set(NumericType.HpBase, config.HP); // 速度 numeric.Set(NumericType.SpeedBase, config.MoveSpeed); // 攻速 numeric.Set(NumericType.AttackSpeedBase, config.AttackSpeed); // 攻击力 numeric.Set(NumericType.HPDamageBase, config.HPDamage); // 警戒范围 numeric.Set(NumericType.AlertRadiusBase, config.AlertRadius); }
protected override void Run(ETModel.Session session, M2C_CreateUnits message) { UnitComponent unitComponent = ETModel.Game.Scene.GetComponent <UnitComponent>(); foreach (UnitInfo unitInfo in message.Units) { if (unitComponent.Get(unitInfo.UnitId) != null) { continue; } UnitData unitData = new UnitData(); unitData.groupIndex = (GroupIndex)unitInfo.GroupIndex; unitData.layerMask = (UnitLayerMask)unitInfo.LayerMask; unitData.unitLayer = (UnitLayer)unitInfo.UnitLayer; unitData.unitTag = (UnitTag)unitInfo.UnitTag; Unit unit = UnitFactory.Create(unitInfo.UnitId, 1001, unitData); NumericComponent numericComponent = unit.GetComponent <NumericComponent>(); foreach (var v in unitInfo.UnitNumerics) { numericComponent.Set((NumericType)v.Type, v.Value); } BattleEventHandler.LoadAssets(unit); Vector3 postion = new Vector3(unitInfo.Position.X, unitInfo.Position.Y, unitInfo.Position.Z); unit.GameObject.transform.forward = new Vector3(unitInfo.Dir.X, unitInfo.Dir.Y, unitInfo.Dir.Z); unit.Position = postion; Dictionary <Type, IProperty> unitStateList = new Dictionary <Type, IProperty>(); P_Position property_Position = new P_Position(); property_Position.Value = postion; // 防止掉下去 unitStateList.Add(typeof(P_Position), property_Position); unit.GetComponent <UnitStateComponent>().Init(unitStateList); } }
public static void Awake(this NumericComponent self, int typeId) { // 这里初始化base值 UnitConfig unitConfig = Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), typeId) as UnitConfig; self.Set(NumericType.ArmorResist, unitConfig.ArmorResist); self.Set(NumericType.ATK, unitConfig.ATK); self.Set(NumericType.CritDamagePct, (float)unitConfig.CritDamagePct); self.Set(NumericType.CritRate, (float)unitConfig.CritRate); self.Set(NumericType.DodgeRate, (float)unitConfig.DodgeRate); self.Set(NumericType.HitRate, (float)unitConfig.HitRate); self.Set(NumericType.HP, unitConfig.HPMax); self.Set(NumericType.HPMax_Base, unitConfig.HPMax); self.Set(NumericType.HP_LeechRate, (float)unitConfig.HP_LeechRate); self.Set(NumericType.HP_Restore, unitConfig.HP_Restore); self.Set(NumericType.Level, unitConfig.Level); self.Set(NumericType.MagicATK, unitConfig.MagicATK); self.Set(NumericType.MagicResist, unitConfig.MagicResist); self.Set(NumericType.MoveSpeed, (float)unitConfig.MoveSpeed); self.Set(NumericType.MP, unitConfig.MPMax); self.Set(NumericType.MPMax_Base, unitConfig.MPMax); self.Set(NumericType.MP_LeechRate, (float)unitConfig.MP_LeechRate); self.Set(NumericType.MP_Restore, unitConfig.MP_Restore); }
public static void SetUnitNumericActionImp(DUnit unit, NumericType numeric, float val) { NumericComponent numericComponent = unit.GetComponent <NumericComponent>(); numericComponent.Set(numeric, val); }
private static void Main(string[] args) { // 异步方法全部会回掉到主线程 OneThreadSynchronizationContext contex = new OneThreadSynchronizationContext(); SynchronizationContext.SetSynchronizationContext(contex); MongoHelper.Init(); try { ObjectEvents.Instance.Add("Model", typeof(Game).Assembly); ObjectEvents.Instance.Add("Hotfix", DllHelper.GetHotfixAssembly()); Options options = Game.Scene.AddComponent <OptionComponent, string[]>(args).Options; StartConfig startConfig = Game.Scene.AddComponent <StartConfigComponent, string, int>(options.Config, options.AppId).StartConfig; if (!options.AppType.Is(startConfig.AppType)) { Log.Error("命令行参数apptype与配置不一致"); return; } IdGenerater.AppId = options.AppId; LogManager.Configuration.Variables["appType"] = startConfig.AppType.ToString(); LogManager.Configuration.Variables["appId"] = startConfig.AppId.ToString(); LogManager.Configuration.Variables["appTypeFormat"] = $"{startConfig.AppType,-8}"; LogManager.Configuration.Variables["appIdFormat"] = $"{startConfig.AppId:D3}"; Log.Info("server start........................"); Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <MessageDispatherComponent>(); Unit unit = new Unit(); NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); numericComponent.Set(NumericType.Speed, 100); Log.Debug(MongoHelper.ToJson(unit)); Unit unit2 = MongoHelper.FromJson <Unit>(MongoHelper.ToJson(unit)); Log.Debug(MongoHelper.ToJson(unit2)); // 根据不同的AppType添加不同的组件 OuterConfig outerConfig = startConfig.GetComponent <OuterConfig>(); InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>(); ClientConfig clientConfig = startConfig.GetComponent <ClientConfig>(); switch (startConfig.AppType) { case AppType.Manager: Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port); Game.Scene.AddComponent <AppManagerComponent>(); break; case AppType.Realm: Game.Scene.AddComponent <ActorMessageDispatherComponent>(); Game.Scene.AddComponent <ActorManagerComponent>(); Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port); Game.Scene.AddComponent <LocationProxyComponent>(); Game.Scene.AddComponent <RealmGateAddressComponent>(); break; case AppType.Gate: Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <ActorMessageDispatherComponent>(); Game.Scene.AddComponent <ActorManagerComponent>(); Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port); Game.Scene.AddComponent <LocationProxyComponent>(); Game.Scene.AddComponent <ActorProxyComponent>(); Game.Scene.AddComponent <GateSessionKeyComponent>(); break; case AppType.Location: Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <LocationComponent>(); break; case AppType.Map: Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <ActorManagerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <LocationProxyComponent>(); Game.Scene.AddComponent <ActorProxyComponent>(); Game.Scene.AddComponent <ActorMessageDispatherComponent>(); Game.Scene.AddComponent <ServerFrameComponent>(); break; case AppType.AllServer: Game.Scene.AddComponent <ActorProxyComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <DBComponent>(); Game.Scene.AddComponent <DBProxyComponent>(); Game.Scene.AddComponent <LocationComponent>(); Game.Scene.AddComponent <ActorMessageDispatherComponent>(); Game.Scene.AddComponent <ActorManagerComponent>(); Game.Scene.AddComponent <NetInnerComponent, string, int>(innerConfig.Host, innerConfig.Port); Game.Scene.AddComponent <NetOuterComponent, string, int>(outerConfig.Host, outerConfig.Port); Game.Scene.AddComponent <LocationProxyComponent>(); Game.Scene.AddComponent <AppManagerComponent>(); Game.Scene.AddComponent <RealmGateAddressComponent>(); Game.Scene.AddComponent <GateSessionKeyComponent>(); Game.Scene.AddComponent <ConfigComponent>(); Game.Scene.AddComponent <ServerFrameComponent>(); break; case AppType.Benchmark: Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <BenchmarkComponent, string>(clientConfig.Address); break; default: throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}"); } while (true) { try { Thread.Sleep(1); contex.Update(); ObjectEvents.Instance.Update(); } catch (Exception e) { Log.Error(e.ToString()); } } } catch (Exception e) { Log.Error(e.ToString()); } }