private Player() { OnRespondToMission = new Event <int, GameObject, Lot>(); OnFireServerEvent = new Event <string, FireServerEventMessage>(); OnPositionUpdate = new Event <Vector3, Quaternion>(); OnLootPickup = new Event <Lot>(); OnWorldLoad = new Event(); Lock = new SemaphoreSlim(1, 1); Listen(OnStart, async() => { Connection.Disconnected += reason => { Connection = default; Destroy(this); return(Task.CompletedTask); }; Listen(OnPositionUpdate, UpdatePhysics); if (TryGetComponent <DestructibleComponent>(out var destructibleComponent)) { destructibleComponent.OnResurrect.AddListener(() => { GetComponent <DestroyableComponent>().Imagination = 6; }); } await using var ctx = new UchuContext(); var character = await ctx.Characters .Include(c => c.UnlockedEmotes) .FirstAsync(c => c.Id == Id); foreach (var unlockedEmote in character.UnlockedEmotes) { await UnlockEmoteAsync(unlockedEmote.EmoteId); } // Update the player view filters every five seconds Zone.Update(this, async() => { await Perspective.TickAsync(); }, 20 * 5); // Check banned status every minute // TODO: Find an active method instead of polling Zone.Update(this, async() => { await CheckBannedStatusAsync(); }, 20 * 60); });
internal Player() { OnRespondToMission = new Event <int, GameObject, Lot>(); OnFireServerEvent = new Event <string, FireEventServerSideMessage>(); OnReadyForUpdatesEvent = new Event <ReadyForUpdatesMessage>(); OnPositionUpdate = new Event <Vector3, Quaternion>(); OnPetTamingTryBuild = new Event <PetTamingTryBuildMessage>(); OnNotifyTamingBuildSuccessMessage = new Event <NotifyTamingBuildSuccessMessage>(); OnLootPickup = new Event <Lot>(); OnWorldLoad = new Event(); OnSmashObject = new Event <GameObject>(); Listen(OnStart, () => { // Destroy the player on disconnect. // Also check if the player disconnected during loading. if (_loadCancellationToken != default && _loadCancellationToken.IsCancellationRequested) { DestroyAsync().Wait(); return; } Connection.Disconnected += async reason => { await DestroyAsync(); }; Listen(OnPositionUpdate, UpdatePhysics); if (TryGetComponent <DestructibleComponent>(out var destructibleComponent)) { destructibleComponent.OnResurrect.AddListener(() => { GetComponent <DestroyableComponent>().Imagination = 6; }); } // Save the player every 15 seconds Zone.Update(this, () => { // Done in the background as this takes long Task.Run(async() => { Logger.Debug($"Saving {this}."); var timer = new Stopwatch(); timer.Start(); await GetComponent <SaveComponent>().SaveAsync(); timer.Stop(); Logger.Debug($"Saved {this} in {timer.Elapsed:m\\:ss\\.fff}."); });
private Player() { OnFireServerEvent = new AsyncEventDictionary <string, FireServerEventMessage>(); OnPositionUpdate = new Event <Vector3, Quaternion>(); OnLootPickup = new Event <Lot>(); OnWorldLoad = new Event(); Lock = new SemaphoreSlim(1, 1); Listen(OnStart, async() => { Connection.Disconnected += reason => { Connection = default; Destroy(this); return(Task.CompletedTask); }; Listen(OnPositionUpdate, UpdatePhysics); if (TryGetComponent <DestructibleComponent>(out var destructibleComponent)) { destructibleComponent.OnResurrect.AddListener(() => { GetComponent <Stats>().Imagination = 6; }); } await using var ctx = new UchuContext(); var character = await ctx.Characters .Include(c => c.UnlockedEmotes) .FirstAsync(c => c.Id == Id); foreach (var unlockedEmote in character.UnlockedEmotes) { await UnlockEmoteAsync(unlockedEmote.EmoteId); } Zone.Update(this, async() => { await Perspective.TickAsync(); await CheckBannedStatusAsync(); }, 20 * 5); });
public BaseCombatAiComponent() { Listen(OnStart, () => { SkillEntries = new List <NpcSkillEntry>(); Listen(GameObject.OnStart, async() => { SkillComponent = GameObject.GetComponent <SkillComponent>(); DestructibleComponent = GameObject.GetComponent <DestructibleComponent>(); QuickBuildComponent = GameObject.GetComponent <QuickBuildComponent>(); Stats = GameObject.GetComponent <DestroyableComponent>(); foreach (var skillEntry in SkillComponent.DefaultSkillSet) { await using var ctx = new CdClientContext(); var skillInfo = await ctx.SkillBehaviorTable.FirstAsync( s => s.SkillID == skillEntry.SkillId ); await SkillComponent.CalculateSkillAsync((int)skillEntry.SkillId, true); SkillEntries.Add(new NpcSkillEntry { SkillId = skillEntry.SkillId, Cooldown = false, AbilityCooldown = skillInfo.Cooldown ?? 1 }); } Zone.Update(GameObject, async delta => { await CalculateCombat(delta); }, 1); });
public async void StartCombatAI() { SkillComponent = GameObject.GetComponent <SkillComponent>(); DestructibleComponent = GameObject.GetComponent <DestructibleComponent>(); QuickBuildComponent = GameObject.GetComponent <QuickBuildComponent>(); Stats = GameObject.GetComponent <DestroyableComponent>(); foreach (var skillEntry in SkillComponent.DefaultSkillSet) { var skillInfo = await ClientCache.FindAsync <SkillBehavior>(skillEntry.SkillId); SkillEntries.Add(new NpcSkillEntry { SkillId = skillEntry.SkillId, Cooldown = 0, AbilityCooldown = (skillInfo.Cooldown ?? 1) * 1000, Tree = await BehaviorTree.FromSkillAsync((int)skillEntry.SkillId) }); } Zone.Update(GameObject, delta => CalculateCombat(delta), 1); }