Exemplo n.º 1
0
 public static string CreateCharacter(Alignment alignment, Background background, int baseCharisma, int baseConstitution, int baseDexterity, int baseIntelligence, int baseStrength, int baseWisdom, List<Spell> cantrips, CharacterClass chClass, List<Skill> classSkills, List<Skill> classTools, int gender, int hairColor, int hairStyle, string name, Race race, List<Skill> raceSkills, int skinColor, List<Spell> spellsKnown, CharacterClass subClass, List<Power> selectedPowers)
 {
     CharacterCreation chr = new CharacterCreation()
     {
         Alignment = alignment,
         Background = background,
         BaseCharisma = baseCharisma,
         BaseConstitution = baseConstitution,
         BaseDexterity = baseDexterity,
         BaseIntelligence = baseIntelligence,
         BaseStrength = baseStrength,
         BaseWisdom = baseWisdom,
         Cantrips = cantrips,
         Class = chClass,
         ClassSkills = classSkills,
         ClassTools = classTools,
         Gender = gender,
         HairColor = hairColor,
         HairStyle = hairStyle,
         Name = name,
         Race = race,
         RaceSkills = raceSkills,
         SelectedPowers = selectedPowers,
         SessionId = SessionId,
         SkinColor = skinColor,
         SpellsKnown = spellsKnown,
         SubClass = subClass,
         UserId = UserId
     };
     try
     {
         string wrURI = baseServerTarget + "createcharacter";
         string msg = chr.ToString();
         WebRequest wreq = WebRequest.Create(wrURI + "?message=" + msg);
         wreq.Method = "POST";
         wreq.ContentLength = 0;
         WebResponse wresp = wreq.GetResponse();
         using (TextReader sr = new StreamReader(wresp.GetResponseStream()))
         {
             XmlSerializer xml = new XmlSerializer(typeof(string), StringNamespace);
             string resp = (string)xml.Deserialize(sr);
             return resp;
         }
     }
     catch 
     {
         return String.Empty;
     }
 }
Exemplo n.º 2
0
        public CharacterCreation(string buildLine)
        {
            Valid = false;
            string[] buildSplit = buildLine.Split(delim);
            if(buildSplit.Length != 24) { return; }
            Name = buildSplit[0];

            if(!int.TryParse(buildSplit[1], out Gender))
            {
                return;
            }

            uint tempUint = 0;
            if(!uint.TryParse(buildSplit[2], out tempUint))
            {
                return;
            }

            Race = Race.GetRace(tempUint);
            if(Race == null)
            {
                return;
            }

            if(!uint.TryParse(buildSplit[3], out tempUint))
            {
                return;
            }

            Class = CharacterClass.GetClass(tempUint);
            if(Class == null)
            {
                return;
            }

            if(!uint.TryParse(buildSplit[4], out tempUint))
            {
                return;
            }

            Background = Background.GetBackground(tempUint);
            if(Background == null)
            {
                return;
            }

            if(!uint.TryParse(buildSplit[5], out tempUint))
            {
                return;
            }

            Alignment = Alignment.GetAlignment(tempUint);
            if(Alignment == null)
            {
                return;
            }

            RaceSkills = new List<Skill>();
            string[] raceSkillSplit = buildSplit[6].Split(listDelim);
            foreach(string raceSkill in raceSkillSplit)
            {
                if(String.IsNullOrWhiteSpace(raceSkill))
                {
                    continue;
                }

                uint skillId = 0;
                if(!uint.TryParse(raceSkill, out skillId))
                {
                    return;
                }
                Skill toAdd = Skill.GetSkill(skillId);
                if(toAdd == null)
                {
                    return;
                }
                RaceSkills.Add(toAdd);
            }
            if(RaceSkills.Count > Race.FreeSkills)
            {
                return;
            }
            foreach(Skill sk in RaceSkills)
            {
                if(!Race.SelectedSkill.Contains(sk))
                {
                    return;
                }
            }

            ClassSkills = new List<Skill>();
            string[] classSkillSplit = buildSplit[7].Split(listDelim);
            foreach(string classSkill in classSkillSplit)
            {
                if(String.IsNullOrWhiteSpace(classSkill))
                {
                    continue;
                }

                uint skillId = 0;
                if(!uint.TryParse(classSkill, out skillId))
                {
                    return;
                }
                Skill toAdd = Skill.GetSkill(skillId);
                if(toAdd == null)
                {
                    return;
                }
                ClassSkills.Add(toAdd);
            }
            if(ClassSkills.Count > Class.SkillChoices)
            {
                return;
            }
            foreach(Skill sk in ClassSkills)
            {
                if (!Class.AvailableSkills.Contains(sk))
                {
                    return;
                }
            }

            ClassTools = new List<Skill>();
            string[] classToolSplit = buildSplit[8].Split(listDelim);
            foreach(string classTool in classToolSplit)
            {
                if(String.IsNullOrWhiteSpace(classTool))
                {
                    continue;
                }

                uint skillId = 0;
                if(!uint.TryParse(classTool, out skillId))
                {
                    return;
                }
                Skill toAdd = Skill.GetSkill(skillId);
                if(toAdd == null)
                {
                    return;
                }
                ClassTools.Add(toAdd);
            }
            if(ClassTools.Count > Class.ToolChoices)
            {
                return;
            }
            foreach(Skill sk in ClassTools)
            {
                if(!Class.AvailableTools.Contains(sk))
                {
                    return;
                }
            }

            Cantrips = new List<Spell>();
            if (Class.CantripsKnown != null &&
               Class.CantripsKnown.Count > 0)
            {
                string[] cantripsSplit = buildSplit[9].Split(listDelim);
                foreach(string cantrip in cantripsSplit)
                {
                    if(String.IsNullOrWhiteSpace(cantrip))
                    {
                        continue;
                    }

                    uint spellId = 0;
                    if(!uint.TryParse(cantrip, out spellId))
                    {
                        return;
                    }
                    Spell toAdd = Spell.GetSpell(spellId);
                    if(toAdd == null)
                    {
                        return;
                    }
                    Cantrips.Add(toAdd);
                }
                if(Cantrips.Count > Class.CantripsKnown[0])
                {
                    return;
                }
                if (Cantrips.Count > 0)
                {
                    if(Class.SpellList == null)
                    {
                        return;
                    }
                    if (!Class.SpellList.ContainsKey(0))
                    {
                        return;
                    }
                    foreach (Spell sp in Cantrips)
                    {
                        if(!Class.SpellList[0].Contains(sp))
                        {
                            return;
                        }
                    }
                }
            }

            SpellsKnown = new List<Spell>();
            if (Class.SpellsKnown != null &&
                Class.SpellsKnown.Count > 0)
            {
                string[] spellSplit = buildSplit[10].Split(listDelim);
                foreach(string spellKnown in spellSplit)
                {
                    if(String.IsNullOrWhiteSpace(spellKnown))
                    {
                        continue;
                    }
                    uint spellId = 0;
                    if(!uint.TryParse(spellKnown, out spellId))
                    {
                        return;
                    }
                    Spell toAdd = Spell.GetSpell(spellId);
                    if(toAdd == null)
                    {
                        return;
                    }
                    SpellsKnown.Add(toAdd);
                }
                if(SpellsKnown.Count > Class.SpellsKnown[0])
                {
                    return;
                }
                if(SpellsKnown.Count > 0)
                {
                    if(!Class.SpellList.ContainsKey(1))
                    {
                        return;
                    }
                    foreach(Spell sp in SpellsKnown)
                    {
                        if(!Class.SpellList[1].Contains(sp))
                        {
                            return;
                        }
                    }
                }
            }

            if(!int.TryParse(buildSplit[11], out BaseStrength))
            {
                return;
            }
            if(!AbilityScoreCosts.ContainsKey(BaseStrength))
            {
                return;
            }
            if(!int.TryParse(buildSplit[12], out BaseDexterity))
            {
                return;
            }
            if(!AbilityScoreCosts.ContainsKey(BaseDexterity))
            {
                return;
            }
            if(!int.TryParse(buildSplit[13], out BaseConstitution))
            {
                return;
            }
            if(!AbilityScoreCosts.ContainsKey(BaseConstitution))
            {
                return;
            }
            if(!int.TryParse(buildSplit[14], out BaseIntelligence))
            {
                return;
            }
            if(!AbilityScoreCosts.ContainsKey(BaseIntelligence))
            {
                return;
            }
            if(!int.TryParse(buildSplit[15], out BaseWisdom))
            {
                return;
            }
            if(!AbilityScoreCosts.ContainsKey(BaseWisdom))
            {
                return;
            }
            if(!int.TryParse(buildSplit[16], out BaseCharisma))
            {
                return;
            }
            if(!AbilityScoreCosts.ContainsKey(BaseCharisma))
            {
                return;
            }

            if(GetRemainingPoints(BaseStrength, BaseDexterity, BaseConstitution, BaseIntelligence, BaseWisdom, BaseCharisma, Race) < 0)
            {
                return;
            }

            if(!int.TryParse(buildSplit[17], out HairStyle))
            {
                return;
            }
            if(!int.TryParse(buildSplit[18], out HairColor))
            {
                return;
            }
            if(!int.TryParse(buildSplit[19], out SkinColor))
            {
                return;
            }
            UserId = buildSplit[20];

            if(!int.TryParse(buildSplit[21], out SessionId))
            {
                return;
            }

            if(!String.IsNullOrWhiteSpace(buildSplit[22]))
            {
                uint subClassId;
                if (!uint.TryParse(buildSplit[22], out subClassId))
                {
                    CharacterClass sub = CharacterClass.GetClass(subClassId);
                    if (sub == null)
                    {
                        return;
                    }
                    if (Class.SubClasses.Contains(sub))
                    {
                        SubClass = sub;
                    }
                    else
                    {
                        return;
                    }
                }
            }
            else
            {
                SubClass = null;
            }
            if(SubClass == null && Class.SubClassLevel == 1)
            {
                return;
            }
            if(SubClass != null && Class.SubClassLevel != 1)
            {
                return;
            }
            if(Class.SubClassLevel == 1)
            {
                if(!Class.SubClasses.Contains(SubClass))
                {
                    return;
                }
            }

            string[] powerSplit = buildSplit[23].Split(listDelim);
            List<Power> selPow = new List<Power>();
            SelectedPowers = new List<Power>();
            foreach(string powString in powerSplit)
            {
                if(String.IsNullOrWhiteSpace(powString))
                {
                    continue;
                }
                uint powIndex = uint.MaxValue;
                if(!uint.TryParse(powString, out powIndex))
                {
                    return;
                }
                Power toAdd = Power.GetPower(powIndex);
                if(toAdd == null)
                {
                    return;
                }
                selPow.Add(toAdd);
            }

            if(Class.ClassPowers.ContainsKey(1))
            {
                foreach(List<Power> classPowerList in Class.ClassPowers[1])
                {
                    foreach(Power classPower in classPowerList)
                    {
                        if(selPow.Contains(classPower))
                        {
                            selPow.Remove(classPower);
                            SelectedPowers.Add(classPower);
                            break;
                        }
                    }
                }
            }
            if(SubClass != null && Class.ClassPowers.ContainsKey(1))
            {
                foreach (List<Power> classPowerList in SubClass.ClassPowers[1])
                {
                    foreach (Power classPower in classPowerList)
                    {
                        if (selPow.Contains(classPower))
                        {
                            selPow.Remove(classPower);
                            SelectedPowers.Add(classPower);
                            break;
                        }
                    }
                }
            }
            if(selPow.Count > 0)
            {
                return;
            }

            Valid = true;
        }
        private static void CharacterClassBox_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            if(e.IsSelected)
            {
                CharacterClass selectedClass = CharacterClass.GetClass((uint)e.Item.Tag);
                if(selectedClass != null)
                {
                    characterClassText.Text = e.Item.Name;
                    characterClassIcon.BackgroundImage = selectedClass.Icon;

                    if (selectedClass.HitDie == 0)
                    {
                        _selectedSubClass = selectedClass;
                    }
                    else
                    {
                        _selectedSubClass = null;
                        _selectedClass = selectedClass;
                        _classSkills.Clear();
                        _classTools.Clear();
                        _selectedPowers.Clear();
                        UpdateSkills();
                    }
                    if (selectedClass.SubClassLevel == 1)
                    {
                        EditCharacterSubClass(selectedClass);
                    }
                    else
                    {
                        _populateCharacterClassList();
                    }
                    _cantrips.Clear();
                    _firstLevel.Clear();
                    _populateSpellList();
                    _updateCharacterSheetPowers();
                }
            }
        }
        public static void EditCharacterSubClass(CharacterClass selClass)
        {
            characterClassBox.Items.Clear();
            ImageList imgs = new ImageList();
            imgs.ImageSize = IconSize;
            imgs.ColorDepth = ColorDepth.Depth32Bit;

            int imageIndex = 0;

            foreach (CharacterClass cl in selClass.SubClasses)
            {
                ListViewItem toAdd = new ListViewItem(new string[] { "", selClass.Name + ", " + cl.Name });
                toAdd.Name = selClass.Name + ", " + cl.Name;
                toAdd.ImageIndex = imageIndex;
                toAdd.Tag = cl.Id;
                toAdd.ToolTipText = StringLibrary.GetString(cl.Description);
                imgs.Images.Add(cl.Icon);
                imageIndex++;
                StyleListViewItem(toAdd);
                characterClassBox.Items.Add(toAdd);
            }
            characterClassBox.SmallImageList = imgs;
        }
Exemplo n.º 5
0
 public static void Load()
 {
     string file = System.IO.Directory.GetCurrentDirectory() + "\\DataArrays\\Classes.txt";
     FileStream strLib = File.Open(file, FileMode.Open);
     using (StreamReader read = new StreamReader(strLib, Encoding.UTF7))
     {
         while (read.Peek() >= 0)
         {
             CharacterClass toAdd = new CharacterClass(read.ReadLine());
             _library.Add(toAdd.Id, toAdd);
         }
     }
     // Link up subclasses and spell lists.
     foreach(CharacterClass cl in _library.Values)
     {
         cl.SpellList = Mundasia.Objects.SpellList.GetSpellList(cl.Id);
         foreach(uint subClassId in cl._subClassIds)
         {
             CharacterClass scl = CharacterClass.GetClass(subClassId);
             if (scl != null) cl.SubClasses.Add(scl);
         }
     }
 }