internal static Ability9 AddAbility(Ability ability) { try { if (!abilityTypes.TryGetValue(ability.Id, out var type)) { return(null); } var newAbility = GetAbilityFast(ability.Handle); if (newAbility != null) { return(newAbility); } var abilityOwner = GetUnitFast(ability.Owner?.Handle); if (abilityOwner == null) { DelayedAdd(ability); return(null); } if (ability is Item item) { if (item.PurchaseTime < 0) { // created by lotus return(null); } } else if (ability.AbilitySlot < 0 && !ability.IsHidden) { // created by lotus return(null); } newAbility = (Ability9)Activator.CreateInstance(type, ability); newAbility.SetPrediction(predictionManager); AbilityMonitor.SetOwner(newAbility, abilityOwner); SaveAbility(newAbility); abilityAdded?.Invoke(newAbility); return(newAbility); } catch (Exception e) { Logger.Error(e, ability); return(null); } }
static EntityManager9() { foreach (var type in Assembly.GetExecutingAssembly().GetTypes().Where(x => !x.IsAbstract && x.IsClass)) { if (typeof(Ability9).IsAssignableFrom(type)) { foreach (var attribute in type.GetCustomAttributes <AbilityIdAttribute>()) { abilityTypes.Add(attribute.AbilityId, type); } } else if (typeof(Hero9).IsAssignableFrom(type)) { foreach (var attribute in type.GetCustomAttributes <HeroIdAttribute>()) { heroTypes.Add(attribute.HeroId, type); } } else if (typeof(Unit9).IsAssignableFrom(type)) { foreach (var attribute in type.GetCustomAttributes <UnitNameAttribute>()) { unitTypes.Add(attribute.Name, type); } } } Owner = new Owner(); UnitMonitor = new UnitMonitor(); AbilityMonitor = new AbilityMonitor(); delayedEntityHandler = UpdateManager.CreateIngameUpdate(1000, false, DelayedEntitiesOnUpdate); AddCurrentUnits(); AddCurrentAbilities(); EntityManager.EntityAdded += OnEntityAdded; EntityManager.EntityRemoved += OnEntityRemoved; UpdateManager.BeginInvoke(2000, DemoModeCheck); UpdateManager.BeginInvoke(5000, LoadCheck); }
static EntityManager9() { foreach (var type in Assembly.GetExecutingAssembly().GetTypes().Where(x => !x.IsAbstract && x.IsClass)) { if (typeof(Ability9).IsAssignableFrom(type)) { foreach (var attribute in type.GetCustomAttributes <AbilityIdAttribute>()) { abilityTypes.Add(attribute.AbilityId, type); } } else if (typeof(Hero9).IsAssignableFrom(type)) { foreach (var attribute in type.GetCustomAttributes <HeroIdAttribute>()) { heroTypes.Add(attribute.HeroId, type); } } else if (typeof(Unit9).IsAssignableFrom(type)) { foreach (var attribute in type.GetCustomAttributes <UnitNameAttribute>()) { unitTypes.Add(attribute.Name, type); } } } Owner = new Owner(); UnitMonitor = new UnitMonitor(); AbilityMonitor = new AbilityMonitor(); delayedEntityHandler = UpdateManager.Subscribe(DelayedEntitiesOnUpdate, 1000, false); AddCurrentUnits(); AddCurrentAbilities(); ObjectManager.OnAddEntity += OnAddEntity; ObjectManager.OnRemoveEntity += OnRemoveEntity; UpdateManager.BeginInvoke(DemoModeCheck, 2000); UpdateManager.BeginInvoke(LoadCheck, 5000); }