public void OnEntityRegistered(object sender, EntityRegistryComponent.EntityEventArgs e) { this.Log(e.Entity.Map ? $"Location registering {e.Entity}" : $"Location spawning {e.Entity}"); e.Entity.SetLocation(this); if (!e.Entity.Map) { e.Entity.SetCell(EntryCell); } if (AssociatedMap) { AssociatedMap.EntityRegistry.Register(e.Entity); } if (!e.Entity.Map) { EntitySpawned?.Invoke(this, new EntityRegistryComponent.EntityEventArgs(e.Entity)); return; } EntityArrived?.Invoke(this, new EntityRegistryComponent.EntityEventArgs(e.Entity)); }
public Entity SpawnEntity(EntityAsset asset, Team owner, Vector2 position, Quaternion?rotation = null, Transform parent = null) { parent = parent ?? GameManager.instance.ingameObject.transform; var prefab = asset.entityPrefab; if (prefab == null) { throw new ArgumentException($"{asset.entityPrefab.GetType().Name} does not have the same type as {asset.objectType.Name}!"); } var result = Instantiate(prefab, position, rotation ?? new Quaternion(), parent) .GetComponent <Entity>(); result.Initiate(asset, owner); if (!entities.TryGetValue(owner, out var value)) { value = new List <Entity>(); entities.Add(owner, value); } value.Add(result); EntitySpawned?.Invoke(this, result); return(result); }
/*----------------------------------------------------------------------------------------- * Entity creation * -----------------------------------------------------------------------------------------*/ /// <summary> /// /// </summary> /// <param name="factory"></param> /// <param name="classID"></param> /// <param name="parentId"></param> /// <param name="origin"></param> /// <param name="orient"></param> /// <returns></returns> public Entity Spawn(EntityFactory factory, short classID, uint parentId, Vector3 origin, Quaternion orient, string targetName) { // get ID : uint id = idCounter; idCounter++; if (idCounter == 0) { // this actually will never happen, about 103 day of intense playing. throw new InvalidOperationException("Too much entities were spawned"); } // // Create instance. // If creation failed later, entity become dummy. // var entity = new Entity(id, classID, parentId, origin, orient, targetName); entities.Add(id, entity); entity.Controller = factory?.Spawn(entity, this); EntitySpawned?.Invoke(this, new EntityEventArgs(entity)); return(entity); }
public Entity Spawn(GameObject prefab, Vector2Int entityPosition, Direction entityOrientation) { if (prefab == null) { Debug.LogWarning($"Trying to spawn null prefab at {entityPosition}"); return(null); } var prefabEntity = prefab.GetComponent <Entity>(); if (prefabEntity == null) { Debug.LogWarning($"Prefab {prefab} missing Entity Component"); return(null); } var spawnedObject = Instantiate(prefab, Utils.LevelToWorld(entityPosition), Utils.DirectionToRotation(entityOrientation)); var entity = spawnedObject.GetComponent <Entity>(); if (entity != null) { var newEntityId = GetNewEntityId(); entity.Initialize(this, newEntityId); _entities.Add(newEntityId, entity); EntitySpawned?.Invoke(entity); return(entity); } Debug.LogWarning($"Failed to spawn prefab {prefab}"); return(null); }
public string SpawnPlayerEntity(string playerid) { var player = _players.FindOne(x => x.ItchUserId == playerid); if (player != null) { return(null); } var entity = new Entity { Id = Guid.NewGuid().ToString(), IsNPC = false, DisplayName = "", Description = "" }; _entities.Insert(entity); _players.Insert(new PlayerEntityMap { Id = Guid.NewGuid().ToString(), EntityId = entity.Id, ItchUserId = playerid }); Plex.Objects.Logger.Log("Spawned new player entity for " + playerid); EntitySpawned?.Invoke(entity.Id, entity); return(entity.Id); }
private void AddEntity(IEntity entity) { if (!_entities.Add(entity)) { return; } entity.WorldChanged += OnEntityWorldChanged; entity.Removed += OnEntityRemoved; EntitySpawned?.Invoke(this, new EntityEventArgs(entity)); }
public string SpawnNPCEntity(string name, string description) { var existing = _entities.FindOne(x => x.DisplayName == name && x.Description == description); if (existing != null) { return(existing.Id); } var entity = new Entity { Id = Guid.NewGuid().ToString(), IsNPC = true, DisplayName = name, Description = description }; _entities.Insert(entity); EntitySpawned?.Invoke(entity.Id, entity); return(entity.Id); }
internal void OnEntitySpawn(Entity val) { EntitySpawned?.Invoke(val); }
void OnEnable() { EntitySpawned?.Invoke(this); }
private void HandleCurrentEvents() { foreach (BaseEvent baseEvent in currentTick.Events) { switch (baseEvent.Type) { case EventType.MatchStarted: MatchStarted?.Invoke(this, baseEvent); break; case EventType.RoundAnnounceMatchStarted: break; case EventType.RoundStart: RoundStart?.Invoke(this, (RoundStartEvent)baseEvent); break; case EventType.RoundEnd: RoundEnd?.Invoke(this, (RoundEndEvent)baseEvent); break; case EventType.WinPanelMatch: WinPanelMatch?.Invoke(this, baseEvent); break; case EventType.RoundFinal: break; case EventType.LastRoundHalf: break; case EventType.RoundOfficiallyEnd: RoundOfficiallyEnd?.Invoke(this, baseEvent); break; case EventType.RoundMVP: RoundMVP?.Invoke(this, (RoundMVPEvent)baseEvent); break; case EventType.FreezetimeEnded: FreezetimeEnded?.Invoke(this, baseEvent); break; case EventType.PlayerKilled: PlayerKilled?.Invoke(this, (PlayerKilledEvent)baseEvent); break; case EventType.PlayerTeam: PlayerTeam?.Invoke(this, (PlayerTeamEvent)baseEvent); break; case EventType.WeaponFired: WeaponFired?.Invoke(this, (WeaponFiredEvent)baseEvent); break; case EventType.SmokeNadeStarted: SmokeNadeStarted?.Invoke(this, (SmokeNadeStartedEvent)baseEvent); break; case EventType.SmokeNadeEnded: SmokeNadeEnded?.Invoke(this, (SmokeNadeEndedEvent)baseEvent); break; case EventType.DecoyNadeStarted: DecoyNadeStarted?.Invoke(this, (DecoyNadeStartedEvent)baseEvent); break; case EventType.DecoyNadeEnded: DecoyNadeEnded?.Invoke(this, (DecoyNadeEndedEvent)baseEvent); break; case EventType.FireNadeStarted: FireNadeStarted?.Invoke(this, (FireNadeStartedEvent)baseEvent); break; case EventType.FireNadeWithOwnerStarted: FireNadeWithOwnerStarted?.Invoke(this, (FireNadeWithOwnerStartedEvent)baseEvent); break; case EventType.FireNadeEnded: FireNadeEnded?.Invoke(this, (FireNadeEndedEvent)baseEvent); break; case EventType.FlashNadeExploded: FlashNadeExploded?.Invoke(this, (FlashNadeExplodedEvent)baseEvent); break; case EventType.ExplosiveNadeExploded: ExplosiveNadeExploded?.Invoke(this, (ExplosiveNadeExplodedEvent)baseEvent); break; case EventType.NadeReachedTarget: NadeReachedTarget?.Invoke(this, (NadeReachedTargetEvent)baseEvent); break; case EventType.BombBeginPlant: BombBeginPlant?.Invoke(this, (BombBeginPlantEvent)baseEvent); break; case EventType.BombAbortPlant: BombAbortPlant?.Invoke(this, (BombAbortPlantEvent)baseEvent); break; case EventType.BombPlanted: BombPlanted?.Invoke(this, (BombPlantedEvent)baseEvent); break; case EventType.BombDefused: BombDefused?.Invoke(this, (BombDefusedEvent)baseEvent); break; case EventType.BombExploded: BombExploded?.Invoke(this, (BombExplodedEvent)baseEvent); break; case EventType.BombBeginDefuse: BombBeginDefuse?.Invoke(this, (BombBeginDefuseEvent)baseEvent); break; case EventType.BombAbortDefuse: BombAbortDefuse?.Invoke(this, (BombAbortDefuseEvent)baseEvent); break; case EventType.PlayerHurt: PlayerHurt?.Invoke(this, (PlayerHurtEvent)baseEvent); break; case EventType.Blind: Blind?.Invoke(this, (BlindEvent)baseEvent); break; case EventType.PlayerBind: PlayerBind?.Invoke(this, (PlayerBindEvent)baseEvent); break; case EventType.PlayerDisconnect: PlayerDisconnect?.Invoke(this, (PlayerDisconnectEvent)baseEvent); break; case EventType.SayText: SayText?.Invoke(this, (SayTextEvent)baseEvent); break; case EventType.SayText2: SayText2?.Invoke(this, (SayText2Event)baseEvent); break; case EventType.PlayerJump: PlayerJump?.Invoke(this, (PlayerJumpEvent)baseEvent); break; case EventType.PlayerFootstep: PlayerFootstep?.Invoke(this, (PlayerFootstepEvent)baseEvent); break; case EventType.OtherDeath: OtherDeath?.Invoke(this, (OtherDeathEvent)baseEvent); break; case EventType.EntitySpawned: EntitySpawned?.Invoke(this, (EntitySpawnedEvent)baseEvent); break; case EventType.EntityRemoved: EntityRemoved?.Invoke(this, (EntityRemovedEvent)baseEvent); break; default: break; } } }