private void OnCharacterAdded(CharacterAddedEvent e) { if (ReferenceEquals(e.character, gameObject)) { Vector3Int tile; if (gameObject.tag == "Human" || gameObject.tag == "Lemming") { Vector3Int gridCenter = new Vector3Int((int)gridManager.Rows / 2, (int)gridManager.Cols / 2, 0); tile = gridManager.GetClosestFreeTile(gridCenter); } else { tile = gridManager.GetRandomFreeBorderTile(); } Vector3 cellCenter = grid.GetCellCenterWorld(tile); Vector2 initialPosition = new Vector2( cellCenter.x, cellCenter.y + yOffset ); transform.position = initialPosition; em.Dispatch(new CharacterMovedEvent { character = gameObject, gridPos = tile }); enabled = false; } }
/// <summary> /// Adds a new character to TCTData.Data.CharList and invokes CharacterAddedEvent /// </summary> /// <param name="character">Character to be added (if not existing)</param> public static void AddCharacter(Character character) { bool found = false; foreach (var cl in CharList) { if (cl.Name == character.Name) { found = true; cl.Laurel = character.Laurel; cl.Level = character.Level; cl.CharClass = character.CharClass; cl.GuildId = character.GuildId; cl.LocationId = character.LocationId; cl.LastOnline = character.LastOnline; cl.AccountId = character.AccountId; cl.Position = character.Position; break; } } if (!found) { // add char to chList CharList.Add(character); // check for TC int tc = 1; if (AccountList.Find(a => a.Id == character.AccountId).TeraClub) { tc = 2; } // initialize dungeons for (int j = 0; j < DungList.Count; j++) { if (DungList[j].ShortName == "AH" || DungList[j].ShortName == "EA" || DungList[j].ShortName == "GL" || DungList[j].ShortName == "CA") { CharList.Last().Dungeons.Add(new CharDungeon(DungList[j].ShortName, DungList[j].MaxBaseRuns, 0)); } else { CharList.Last().Dungeons.Add(new CharDungeon(DungList[j].ShortName, DungList[j].MaxBaseRuns * tc, 0)); } } // create and add strip to list CharacterAddedEvent.Invoke(CharList.Count - 1); //UI.MainWin.CreateStrip(CharList.Count - 1); } }