public CharacterSelection(string builder) { string[] pieces = builder.Split(delim); visibleTiles = Tile.TileCollectionFromString(pieces[0]); CentralCharacter = new Creature(pieces[1]); visibleCharacters = DisplayCharacter.DisplayCharacterCollectionFromString(pieces[2]); }
public static void Set(Form primaryForm, CharacterSelection initialScene) { host = primaryForm; DrivingCharacter = initialScene.CentralCharacter; playScene = new PlayScene(); playScene.Location = new Point(padding, padding); playScene.Size = new Size(host.ClientRectangle.Width - padding * 2, host.ClientRectangle.Height - padding * 2); host.Resize += host_Resize; if(!_eventsInitialized) { _eventsInitialized = true; if (DrivingCharacter.IsGM) { host.KeyDown += playScene_DM_KeyDown; playScene.TileSelected += playScene_DM_TileSelected; } else { host.KeyDown += playScene_KeyDown; playScene.TileSelected += playScene_TileSelected; } } playScene.ViewCenterX = initialScene.CentralCharacter.LocationX; playScene.ViewCenterY = initialScene.CentralCharacter.LocationY; playScene.ViewCenterZ = initialScene.CentralCharacter.LocationZ; host.Controls.Add(playScene); playScene.Add(initialScene.visibleTiles); playScene.Add(initialScene.visibleCharacters); Updater = new BackgroundWorker(); Updater.DoWork += Updater_DoWork; Updater.RunWorkerCompleted += Updater_RunWorkerCompleted; Updater.RunWorkerAsync(); }
public MoveRequest(Creature ch, int x, int y, int z, Direction facing) { AccountName = ch.AccountName; CharacterName = ch.CharacterName; X = x; Y = y; Z = z; Facing = facing; }
public CharacterSelection(Creature character) { if (!Map.LoadedMaps.ContainsKey(character.Map)) { Map.LoadedMaps.Add(character.Map, new Map() { Name = character.Map }); } // We need to check if this character is already present just in case this is a character // relogging. Map currentMap = Map.LoadedMaps[character.Map]; if (!currentMap.PresentCharacters.Contains(character)) { currentMap.AddCharacter(character); } visibleTiles = currentMap.GetNearby(character.LocationX, character.LocationY, character.LocationZ); visibleCharacters = currentMap.GetNearbyCharacters(character.LocationX, character.LocationY, character.LocationZ); CentralCharacter = character; }
public static DisplayCharacter GetDisplayCharacter(Creature ch) { if (ch.CachedDisplay != null && ch.CachedDisplay.x == ch.LocationX && ch.CachedDisplay.y == ch.LocationY && ch.CachedDisplay.z == ch.LocationZ && ch.CachedDisplay.Facing == ch.LocationFacing) { if(ch.Equipment != null && ch.Equipment.ContainsKey((int)InventorySlot.Chest) && ch.Equipment[(int)InventorySlot.Chest].Appearance == ch.CachedDisplay.Clothes && ch.Equipment[(int)InventorySlot.Chest].PrimaryColor == ch.CachedDisplay.ClothColorA && ch.Equipment[(int)InventorySlot.Chest].SecondaryColor == ch.CachedDisplay.ClothColorB) { return ch.CachedDisplay; } else if((ch.Equipment == null || ch.Equipment.ContainsKey((int)InventorySlot.Chest)) && ch.CachedDisplay.Clothes == 0) { return ch.CachedDisplay; } } return new DisplayCharacter(ch); }
private static void SetCharacterDetails(Creature cha) { StringBuilder sb = new StringBuilder(); sb.Append(cha.CharacterName); sb.Append(Environment.NewLine); if(cha.Gender == 0) { sb.Append(StringLibrary.GetString(10)); } else { sb.Append(StringLibrary.GetString(11)); } sb.Append(" "); sb.Append(cha.CharacterRace.Name); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append(StringLibrary.GetString(26)); sb.Append(Environment.NewLine); sb.Append(" "); sb.Append(StringLibrary.GetString(27)); sb.Append(Environment.NewLine); sb.Append(" "); sb.Append(StringLibrary.GetString(28)); sb.Append(Environment.NewLine); sb.Append(" "); sb.Append(StringLibrary.GetString(31) + ": "); sb.Append(" "); sb.Append(StringLibrary.GetString(33) + ": "); sb.Append(Environment.NewLine); sb.Append(" "); sb.Append(StringLibrary.GetString(32) + ": "); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append(StringLibrary.GetString(29)); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append(StringLibrary.GetString(30)); _descriptionBox.Text = sb.ToString(); }
private void Init(Creature toDisplay, bool readOnly) { ShownCharacter = toDisplay; this.Text = ShownCharacter.CharacterName; this.BackColor = Color.Black; this.ForeColor = Color.White; this.Width = 600; this.Height = 700; ReadOnly = readOnly; int currentY= 0; if (readOnly) { LabelName.Text = ShownCharacter.CharacterName; StyleLabel(LabelName); LabelName.Location = new Point(Math.Max(0, (this.Width - LabelName.Width) / 2), padding); Controls.Add(LabelName); currentY = LabelName.Location.Y + LabelName.Height; } else { TextBox ChangeName = new TextBox(); ChangeName.Text = ShownCharacter.CharacterName; StyleLabel(ChangeName); ChangeName.BackColor = Color.DarkGray; ChangeName.Width = 500; ChangeName.Location = new Point(Math.Max(0, (this.Width - ChangeName.Width) / 2), padding); ChangeName.TextChanged += ChangeName_TextChanged; Controls.Add(ChangeName); currentY = ChangeName.Location.Y + ChangeName.Height; } if (readOnly) { LabelSexRace.Text = ShownCharacter.CharacterRace.Name; if (ShownCharacter.Gender == 1) { LabelSexRace.Text += " Male "; } else { LabelSexRace.Text += " Female "; } StyleLabel(LabelSexRace); LabelSexRace.Location = new Point(Math.Max(0, (this.Width - LabelSexRace.Width) / 2), currentY); currentY = LabelSexRace.Location.Y + LabelSexRace.Height; } else { ComboBox ComboRace = new ComboBox(); ComboRace.ForeColor = Color.White; ComboRace.BackColor = Color.Black; ComboRace.Height = ComboRace.PreferredHeight; ComboRace.Width = 90; foreach(Race race in Race.GetRaces()) { ComboRace.Items.Add(race.Name); } ComboRace.AutoCompleteMode = AutoCompleteMode.Suggest; ComboRace.AutoCompleteSource = AutoCompleteSource.CustomSource; ComboRace.AutoCompleteCustomSource = new AutoCompleteStringCollection(); ComboRace.Text = ShownCharacter.CharacterRace.Name; ComboRace.SelectedIndexChanged += ComboRace_SelectedIndexChanged; ComboRace.Location = new Point(100, currentY); this.Controls.Add(ComboRace); ComboBox ComboSex = new ComboBox(); ComboSex.ForeColor = Color.White; ComboSex.BackColor = Color.Black; ComboSex.Height = ComboSex.PreferredHeight; ComboSex.Width = 90; ComboSex.Items.Add("Female"); ComboSex.Items.Add("Male"); ComboSex.AutoCompleteMode = AutoCompleteMode.Suggest; ComboSex.AutoCompleteSource = AutoCompleteSource.CustomSource; ComboSex.AutoCompleteCustomSource = new AutoCompleteStringCollection(); if(ShownCharacter.Gender == 1) { ComboSex.Text = "Male"; } else { ComboSex.Text = "Female"; } ComboSex.SelectedIndexChanged += ComboSex_SelectedIndexChanged; ComboSex.Location = new Point(200, currentY); this.Controls.Add(ComboSex); } LabelAbilityHead.Text = "Abilities"; StyleLabel(LabelAbilityHead); LabelAbilityHead.Location = new Point(Math.Max(0, (this.Width - LabelAbilityHead.Width) / 2), currentY + (padding * 2)); int colWidth = (this.ClientRectangle.Width - (padding * 5)) / 4; LabelPhysicalHead.Text = "Physical"; StyleLabel(LabelPhysicalHead); LabelPhysicalHead.Location = new Point(padding, LabelAbilityHead.Location.Y + LabelAbilityHead.Height); LabelMentalHead.Text = "Mental"; StyleLabel(LabelMentalHead); LabelMentalHead.Location = new Point((padding * 2) + colWidth, LabelAbilityHead.Location.Y + LabelAbilityHead.Height); LabelSocialHead.Text = "Social"; StyleLabel(LabelSocialHead); LabelSocialHead.Location = new Point((padding * 3) + (colWidth * 2), LabelAbilityHead.Location.Y + LabelAbilityHead.Height); LabelSupernaturalHead.Text = "Supernatural"; StyleLabel(LabelSupernaturalHead); LabelSupernaturalHead.Location = new Point((padding * 4) + (colWidth * 3), LabelAbilityHead.Location.Y + LabelAbilityHead.Height); int currentPosY = padding; Controls.Add(LabelSexRace); }
public CharacterPanel(Creature toDisplay, bool readOnly) { Init(toDisplay, readOnly); }
public CharacterPanel(Creature toDisplay) { Init(toDisplay, true); }
public InventoryForm(Creature ch) { ChInv = ch; BroochPanel.Size = IconSize; HelmetPanel.Size = IconSize; LensPanel.Size = IconSize; CloakPanel.Size = IconSize; NeckSlotPanel.Size = IconSize; StonePanel.Size = IconSize; LeftHandPanel.Size = IconSize; ChestPanel.Size = IconSize; RightHandPanel.Size = IconSize; BracerPanel.Size = IconSize; BeltPanel.Size = IconSize; LeftRingPanel.Size = IconSize; GlovePanel.Size = IconSize; BootPanel.Size = IconSize; RightRingPanel.Size = IconSize; BroochPanel.Location = new Point(InventoryPadding, InventoryPadding); HelmetPanel.Location = new Point(BroochPanel.Location.X + BroochPanel.Width + InventoryPadding, InventoryPadding); LensPanel.Location = new Point(HelmetPanel.Location.X + HelmetPanel.Width + InventoryPadding, InventoryPadding); CloakPanel.Location = new Point(BroochPanel.Location.X, BroochPanel.Location.Y + BroochPanel.Height + InventoryPadding); NeckSlotPanel.Location = new Point(HelmetPanel.Location.X, CloakPanel.Location.Y); StonePanel.Location = new Point(LensPanel.Location.X, CloakPanel.Location.Y); LeftHandPanel.Location = new Point(BroochPanel.Location.X, CloakPanel.Location.Y + CloakPanel.Height + InventoryPadding); ChestPanel.Location = new Point(HelmetPanel.Location.X, LeftHandPanel.Location.Y); RightHandPanel.Location = new Point(LensPanel.Location.X, LeftHandPanel.Location.Y); BracerPanel.Location = new Point(BroochPanel.Location.X, LeftHandPanel.Location.Y + LeftHandPanel.Height + InventoryPadding); BeltPanel.Location = new Point(HelmetPanel.Location.X, BracerPanel.Location.Y); LeftRingPanel.Location = new Point(LensPanel.Location.X, BracerPanel.Location.Y); GlovePanel.Location = new Point(BroochPanel.Location.X, BracerPanel.Location.Y + BracerPanel.Height + InventoryPadding); BootPanel.Location = new Point(HelmetPanel.Location.X, GlovePanel.Location.Y); RightRingPanel.Location = new Point(LensPanel.Location.X, GlovePanel.Location.Y); unequippedItems.Location = new Point(InventoryPadding * 4 + IconSize.Width * 3, InventoryPadding); unequippedItems.Width = 300; unequippedItems.Height = InventoryPadding * 4 + IconSize.Height * 5; StyleListView(unequippedItems); this.BackColor = Color.Black; this.Size = new Size(unequippedItems.Location.X + unequippedItems.Width + InventoryPadding + this.Size.Width - this.ClientRectangle.Size.Width, unequippedItems.Location.Y + unequippedItems.Height + InventoryPadding + this.Size.Height - this.ClientRectangle.Size.Height); RefreshInventory(); Controls.Add(NeckSlotPanel); Controls.Add(LeftRingPanel); Controls.Add(RightRingPanel); Controls.Add(LeftHandPanel); Controls.Add(RightHandPanel); Controls.Add(ChestPanel); Controls.Add(BeltPanel); Controls.Add(BroochPanel); Controls.Add(HelmetPanel); Controls.Add(LensPanel); Controls.Add(CloakPanel); Controls.Add(StonePanel); Controls.Add(BracerPanel); Controls.Add(GlovePanel); Controls.Add(BootPanel); Controls.Add(unequippedItems); this.FormClosed += InventoryForm_OnClosed; this.KeyDown += InventoryForm_KeyPress; }
private void equipItem(InventorySlot slot, string identifier) { string ret = ServiceConsumer.EquipItem(PlayerInterface.DrivingCharacter.AccountName, PlayerInterface.DrivingCharacter.CharacterName, ChInv.AccountName, ChInv.CharacterName, identifier, (int)slot); if (ret.StartsWith("Error")) return; else { ChInv = new Creature(ret); RefreshInventory(); return; } }
public string CreateCharacter(string message) { CharacterCreation nChar = new CharacterCreation(message); Account targetAccount = Account.LoadAccount(nChar.UserId); if(targetAccount == null) { return "Invalid account"; } if (targetAccount.SessionId != nChar.SessionId) { return "Invalid session Id"; } if(!nChar.Valid) { return "Character invalid"; } Creature chr; try { chr = new Creature() { AccountName = targetAccount.UserName, Background = nChar.Background, Cantrips = nChar.Cantrips, CharacterAlignment = nChar.Alignment, CharacterName = nChar.Name, CharacterRace = nChar.Race, Classes = new Dictionary<CharacterClass, uint>() { { nChar.Class, 1 } }, Gender = nChar.Gender, Equipment = new Dictionary<int, InventoryItem>(), Inventory = new List<InventoryItem>(), Powers = nChar.SelectedPowers, ProficiencyBonus = 2, ProficientSaves = nChar.Class.ProficientSaves, SpellsKnown = nChar.SpellsKnown, SubClasses = new Dictionary<CharacterClass, CharacterClass>() { { nChar.Class, nChar.SubClass } }, Strength = nChar.BaseStrength + nChar.Race.Strength, Dexterity = nChar.BaseDexterity + nChar.Race.Dexterity, Constitution = nChar.BaseConstitution + nChar.Race.Constitution, Intelligence = nChar.BaseIntelligence + nChar.Race.Intelligence, Wisdom = nChar.BaseWisdom + nChar.Race.Wisdom, Charisma = nChar.BaseCharisma + nChar.Race.Charisma, SkinColor = (uint)nChar.SkinColor, HairColor = (uint)nChar.HairColor, HairStyle = (uint)nChar.HairStyle, }; } catch { return "Invalid character data; likely a negative number passed to an unsigned field."; } if(!chr.ValidateCharacter()) { return "Could not validate created character."; } chr.Skills = new List<Skill>(); chr.Skills.AddRange(nChar.ClassSkills); chr.Skills.AddRange(nChar.ClassTools); chr.Skills.AddRange(nChar.RaceSkills); chr.Skills.AddRange(nChar.Race.AutomaticSkills); chr.Powers.AddRange(nChar.Race.Powers); if (nChar.Class.ClassPowers.ContainsKey(1)) { foreach(List<Power> pow in nChar.Class.ClassPowers[1]) { if(pow.Count == 1) { chr.Powers.AddRange(pow); } } } if (nChar.SubClass != null && nChar.SubClass.ClassPowers.ContainsKey(1)) { foreach (List<Power> pow in nChar.SubClass.ClassPowers[1]) { if (pow.Count == 1) { chr.Powers.AddRange(pow); } } } InventoryItem it = InventoryItem.SpawnItem(2.ToString("X20")); chr.Equipment.Add((int)InventorySlot.Chest, it); if (targetAccount.LoadCharacter(chr.CharacterName) != null) { return "A character with that name already exists"; } if (!targetAccount.NewCharacter(chr)) { return "Unable to attach character to account"; } if (!targetAccount.SaveCharacter(chr)) { return "Unable to save character"; } return "Success: " + chr.CharacterName; }
/// <summary> /// Create a character for this account with the chr character object. /// /// Assumes that the character object has passed validation. /// </summary> /// <param name="chr">The character to add to this account</param> /// <returns>true on success, or false on failure</returns> public bool NewCharacter(Creature chr) { chr.AccountName = this.UserName; Characters.Add(chr.CharacterName); LoadedCharacters.Add(chr); return SaveCharacter(chr); }
public bool ChangeCharacterAppearance(Creature ch) { DisplayCharacter dch = DisplayCharacter.GetDisplayCharacter(ch); foreach(Creature observer in PresentCharacters) { if (!MapDeltas.ContainsKey(observer)) { MapDeltas.Add(observer, new MapDelta()); } if (MapDeltas[observer].ChangedCharacters.ContainsKey(dch.CharacterId)) { MapDeltas[observer].ChangedCharacters[dch.CharacterId] = dch; } else { MapDeltas[observer].ChangedCharacters.Add(dch.CharacterId, dch); } if (MapDeltas[observer].RemovedCharacters.ContainsKey(dch.CharacterId)) { MapDeltas[observer].RemovedCharacters.Remove(dch.CharacterId); } } return true; }
public bool MoveCharacter(Creature ch, int X, int Y, int Z, Direction Facing) { Tile targetTile = GetTileExact(X, Y, Z); if(targetTile != null) { int characterHeight = ch.CharacterRace.Height; int testedHeight = characterHeight; while(testedHeight > 0) { if(GetTileOverlap(X, Y, Z + testedHeight) != null) { return false; } testedHeight--; } ch.LocationX = X; ch.LocationY = Y; ch.LocationZ = Z; ch.LocationFacing = Facing; DisplayCharacter dch = DisplayCharacter.GetDisplayCharacter(ch); foreach(Creature observer in PresentCharacters) { if(!MapDeltas.ContainsKey(observer)) { MapDeltas.Add(observer, new MapDelta()); } if (MapDeltas[observer].ChangedCharacters.ContainsKey(dch.CharacterId)) { MapDeltas[observer].ChangedCharacters[dch.CharacterId] = dch; } else { MapDeltas[observer].ChangedCharacters.Add(dch.CharacterId, dch); } if (MapDeltas[observer].RemovedCharacters.ContainsKey(dch.CharacterId)) { MapDeltas[observer].RemovedCharacters.Remove(dch.CharacterId); } } return true; } return false; }
/// <summary> /// Saves a character object /// </summary> /// <param name="chr">The character to save</param> /// <returns>true on success, false on failure</returns> public bool SaveCharacter(Creature chr) { try { string path = GetPathForId(UserName); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if(!Characters.Contains(chr.CharacterName)) { Characters.Add(chr.CharacterName); } using (FileStream stream = new FileStream(path + chr.CharacterName + ".chr", FileMode.Create)) { using (StreamWriter sr = new StreamWriter(stream)) { sr.WriteLine(chr.ToString()); sr.Flush(); } } _lastAccessed = DateTime.UtcNow; SaveAccount(); return true; } catch { return false; } }
/// <summary> /// Loads a character by the character's name /// </summary> /// <param name="characterName">The character to load</param> /// <returns>The character object of the loaded object, or null on failure</returns> public Creature LoadCharacter(string characterName) { _lastAccessed = DateTime.UtcNow; foreach (Creature ch in LoadedCharacters) { if (ch.CharacterName == characterName) { return ch; } } string path = GetPathForId(UserName); if (!Directory.Exists(path)) { return null; } try { using (FileStream stream = new FileStream(path + characterName + ".chr", FileMode.Open)) { using (StreamReader sr = new StreamReader(stream)) { Creature ret = new Creature(sr.ReadLine()); LoadedCharacters.Add(ret); return ret; } } } catch { return null; } }
static void _characterList_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { if(e.IsSelected) { string ret = Mundasia.Communication.ServiceConsumer.CharacterDetails(e.Item.SubItems[0].Text); Creature ch = new Creature(ret); SetCharacterDetails(ch); } }
private DisplayCharacter(Creature ch) { if(ch.CachedDisplay == null) { CharacterId = currentId++; } else { CharacterId = ch.CachedDisplay.CharacterId; } Height = ch.CharacterRace.Height; x = ch.LocationX; y = ch.LocationY; z = ch.LocationZ; Facing = ch.LocationFacing; CharacterRace = ch.CharacterRace.Id; SkinColor = (int)ch.SkinColor; HairColor = (int)ch.HairColor; Sex = ch.Gender; Hair = (int)ch.HairStyle; if(ch.Equipment != null && ch.Equipment.ContainsKey((int)InventorySlot.Chest)) { InventoryItem clothes = ch.Equipment[(int)InventorySlot.Chest]; Clothes = clothes.Appearance; ClothColorA = clothes.PrimaryColor; ClothColorB = clothes.SecondaryColor; } ch.CachedDisplay = this; }