Skip to content

Commit

Permalink
Web version
Browse files Browse the repository at this point in the history
  • Loading branch information
Grauenwolf committed Nov 23, 2017
1 parent 8541f79 commit 433f3a0
Show file tree
Hide file tree
Showing 126 changed files with 37,249 additions and 16,652 deletions.
42 changes: 36 additions & 6 deletions SavageTools/SavageTools.Shared/CharacterGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,21 @@ namespace SavageTools

public class CharacterGenerator : ModelBase
{
public CharacterGenerator(FileInfo setting)
{
LoadSetting(setting);

NameService = new LocalNameService(setting.DirectoryName, NamePrefix);
PersonalityService = new PersonalityService(setting.DirectoryName);
}

public LocalNameService NameService = new LocalNameService("Settings");
public PersonalityService PersonalityService = new PersonalityService("Settings");
public bool UseStrain { get => Get<bool>(); set => Set(value); }
public bool UseReason { get => Get<bool>(); set => Set(value); }
public bool UseStatus { get => Get<bool>(); set => Set(value); }
public string NamePrefix { get => Get<string>(); set => Set(value); }

public LocalNameService NameService;
public PersonalityService PersonalityService;

public ObservableCollectionExtended<string> Settings { get; } = new ObservableCollectionExtended<string>();

Expand Down Expand Up @@ -93,9 +105,9 @@ public SettingArchetype SelectedArchetype
public bool WildCard { get { return GetDefault(false); } set { Set(value); } }


public Character GenerateCharacter()
public Character GenerateCharacter(Dice dice = null)
{
var dice = new Dice();
dice = dice ?? new Dice();

if (RandomArchetype)
{
Expand All @@ -117,7 +129,7 @@ public Character GenerateCharacter()
}


var result = new Character() { Rank = SelectedRank.Name, IsWildCard = WildCard };
var result = new Character() { Rank = SelectedRank.Name, IsWildCard = WildCard, UseReason = UseReason, UseStatus = UseStatus, UseStrain = UseStrain };

var name = NameService.CreateRandomPerson(dice);
result.Name = name.FullName;
Expand Down Expand Up @@ -235,7 +247,7 @@ public Character GenerateCharacter()
//Add personality
int personalityTraits = dice.D(3);
for (var i = 0; i < personalityTraits; i++)
result.Features.Add(PersonalityService.CreateRandomPersonality(dice));
result.Personality.Add(PersonalityService.CreateRandomPersonality(dice));

return result;
}
Expand Down Expand Up @@ -299,8 +311,14 @@ void ApplyArchetype(Character result, Dice dice)

if (SelectedArchetype.Gear != null)
foreach (var item in SelectedArchetype.Gear)
{
result.Gear.Add(item.Name, item.Description);

if (item.Traits != null)
foreach (var trait in item.Traits)
result.Increment(trait.Name, trait.Bonus, dice);
}

}
void ApplyRace(Character result, Dice dice)
{
Expand Down Expand Up @@ -409,6 +427,7 @@ static void ApplyEdge(Character result, SettingEdge edge, Dice dice)

static readonly XmlSerializer SettingXmlSerializer = new XmlSerializer(typeof(Setting));


public void LoadSetting(FileInfo file)
{
var currentArchetype = SelectedArchetype?.Name;
Expand All @@ -427,6 +446,15 @@ public void LoadSetting(FileInfo file)
if (book.BornAHero)
BornAHero = true;

if (book.UseReason)
UseReason = true;

if (book.UseStatus)
UseStatus = true;

if (book.UseStrain)
UseStrain = true;

if (book.References != null)
foreach (var item in book.References.Where(r => !Settings.Any(s => s == r.Name)))
{
Expand Down Expand Up @@ -501,6 +529,8 @@ public void LoadSetting(FileInfo file)

if (currentRank != null && SelectedRank == null) //selected rank was replaced so we need to reselect it
SelectedRank = Ranks.Single(a => a.Name == currentRank);

NamePrefix = book.NamePrefix;
}
void PickHindrance(Character result, Dice dice)
{
Expand Down
256 changes: 124 additions & 132 deletions SavageTools/SavageTools.Shared/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,156 +7,77 @@ namespace SavageTools.Characters
{
public class Character : ChangeTrackingModelBase
{
public string Name { get { return Get<string>(); } set { Set(value); } }
public string Gender { get { return Get<string>(); } set { Set(value); } }
public Trait Agility { get { return Get<Trait>(); } set { Set(value); } }
public Trait Smarts { get { return Get<Trait>(); } set { Set(value); } }
public Trait Strength { get { return Get<Trait>(); } set { Set(value); } }
public Trait Spirit { get { return Get<Trait>(); } set { Set(value); } }
public Trait Vigor { get { return Get<Trait>(); } set { Set(value); } }



public Trait MaxAgility { get { return GetDefault<Trait>(12); } set { Set(value); } }
public Trait MaxSmarts { get { return GetDefault<Trait>(12); } set { Set(value); } }
public Trait MaxStrength { get { return GetDefault<Trait>(12); } set { Set(value); } }
public Trait MaxSpirit { get { return GetDefault<Trait>(12); } set { Set(value); } }
public Trait MaxVigor { get { return GetDefault<Trait>(12); } set { Set(value); } }

public SkillCollection Skills { get { return GetNew<SkillCollection>(); } }
public HindranceCollection Hindrances { get { return GetNew<HindranceCollection>(); } }
public EdgeCollection Edges { get { return GetNew<EdgeCollection>(); } }
public FeatureCollection Features { get { return GetNew<FeatureCollection>(); } }
public GearCollection Gear { get { return GetNew<GearCollection>(); } }

public int Experience { get { return Get<int>(); } set { Set(value); } }

public int UnusedAttributes { get { return Get<int>(); } set { Set(value); } }
public int UnusedSkills { get { return Get<int>(); } set { Set(value); } }
public int UnusedSmartSkills { get { return Get<int>(); } set { Set(value); } }
public int UnusedEdges { get { return Get<int>(); } set { Set(value); } }
public int UnusedRacialEdges { get { return Get<int>(); } set { Set(value); } }
public int UnusedIconicEdges { get { return Get<int>(); } set { Set(value); } }
public int UnusedHindrances { get { return Get<int>(); } set { Set(value); } }
public int UnusedAdvances { get { return Get<int>(); } set { Set(value); } }



public bool IsWildCard { get { return Get<bool>(); } set { Set(value); } }

public Trait Agility { get => Get<Trait>(); set => Set(value); }
public string Archetype { get { return Get<string>(); } set { Set(value); } }
public string Race { get { return Get<string>(); } set { Set(value); } }
public string Rank { get { return Get<string>(); } set { Set(value); } }

public int Pace { get { return GetDefault(6); } set { Set(value); } }
public Trait Running { get { return GetDefault<Trait>(6); } set { Set(value); } }

public int Charisma { get { return Get<int>(); } set { Set(value); } }
public int Parry { get { return Get<int>(); } set { Set(value); } }
public int Toughness { get { return Get<int>(); } set { Set(value); } }
public int Strain { get { return Get<int>(); } set { Set(value); } }
public EdgeCollection Edges => GetNew<EdgeCollection>();
public int Experience { get => Get<int>(); set => Set(value); }
public FeatureCollection Features => GetNew<FeatureCollection>();
public PersonalityCollection Personality => GetNew<PersonalityCollection>();
public GearCollection Gear => GetNew<GearCollection>();
public string Gender { get => Get<string>(); set => Set(value); }
public HindranceCollection Hindrances => GetNew<HindranceCollection>();
public bool IsWildCard { get { return Get<bool>(); } set { Set(value); } }
public Trait MaxAgility { get => GetDefault<Trait>(12); set => Set(value); }
public int MaximumStrain { get { return Get<int>(); } set { Set(value); } }

public int Status { get { return GetDefault(2); } set { Set(value); } }
public int Reason { get { return Get<int>(); } set { Set(value); } }
public int Size { get { return Get<int>(); } set { Set(value); } }

[CalculatedField("Reason,Spirit")]
public int ReasonTotal
[CalculatedField("MaximumStrain,Spirit,Vigor")]
public int MaximumStrainTotal
{
get { return 2 + Spirit.HalfScore + Reason; }
get { return MaximumStrain + Math.Min(Spirit.Score, Vigor.Score); }
}


public Trait MaxSmarts { get => GetDefault<Trait>(12); set => Set(value); }
public Trait MaxSpirit { get => GetDefault<Trait>(12); set => Set(value); }
public Trait MaxStrength { get => GetDefault<Trait>(12); set => Set(value); }
public Trait MaxVigor { get => GetDefault<Trait>(12); set => Set(value); }
public string Name { get => Get<string>(); set => Set(value); }
public int Pace { get { return GetDefault(6); } set { Set(value); } }
public int Parry { get { return Get<int>(); } set { Set(value); } }
public int ParryTotal
{
get { return 2 + (Skills.SingleOrDefault(s => s.Name == "Fighting")?.Trait.HalfScore ?? 0); }
}

[CalculatedField("Vigor")]
public int ToughnessTotal
{
get { return 2 + Vigor.HalfScore + Toughness; }
}

[CalculatedField("MaximumStrain,Spirit,Vigor")]
public int MaximumStrainTotal
public PowerGroupCollection PowerGroups => GetNew<PowerGroupCollection>();
public string Race { get { return Get<string>(); } set { Set(value); } }
public string Rank { get { return Get<string>(); } set { Set(value); } }
public int Reason { get { return Get<int>(); } set { Set(value); } }
[CalculatedField("Reason,Spirit")]
public int ReasonTotal
{
get { return MaximumStrain + Math.Min(Spirit.Score, Vigor.Score); }
get { return 2 + Spirit.HalfScore + Reason; }
}

public void Increment(string trait, Dice dice)
{
Increment(trait, 1, dice);
}
public Trait Running { get { return GetDefault<Trait>(6); } set { Set(value); } }
public int Size { get { return Get<int>(); } set { Set(value); } }
public SkillCollection Skills => GetNew<SkillCollection>();
public Trait Smarts { get => Get<Trait>(); set => Set(value); }
public Trait Spirit { get => Get<Trait>(); set => Set(value); }
public int Status { get { return GetDefault(2); } set { Set(value); } }
public int Strain { get { return Get<int>(); } set { Set(value); } }
public Trait Strength { get => Get<Trait>(); set => Set(value); }
public int Toughness { get { return Get<int>(); } set { Set(value); } }

public void Increment(string trait, int bonus, Dice dice)
[CalculatedField("Vigor,Armor,Toughness")]
public int ToughnessTotal
{
switch (trait)
{
case "Vigor": Vigor += bonus; return;
case "Smarts": Smarts += bonus; return;
case "Agility": Agility += bonus; return;
case "Strength": Strength += bonus; return;
case "Spirit": Spirit += bonus; return;

case "MaxVigor": MaxVigor += bonus; return;
case "MaxSmarts": MaxSmarts += bonus; return;
case "MaxAgility": MaxAgility += bonus; return;
case "MaxStrength": MaxStrength += bonus; return;
case "MaxSpirit": MaxSpirit += bonus; return;

case "Pace": Pace += bonus; return;
case "Running": Running += bonus; return;
case "Charisma": Charisma += bonus; return;
case "Parry": Parry += bonus; return;
case "Toughness": Toughness += bonus; return;
case "Strain": Strain += bonus; return;
case "MaximumStrain": MaximumStrain += bonus; return;
case "Reason": Reason += bonus; return;
case "Status": Status += bonus; return;
case "Size": Size += bonus; return;


case "UnusedAttributes": UnusedAttributes += bonus; return;
case "UnusedSkills": UnusedSkills += bonus; return;
case "UnusedSmartSkills": UnusedSmartSkills += bonus; return;
case "UnusedEdges": UnusedEdges += bonus; return;
case "UnusedRacialEdges": UnusedRacialEdges += bonus; return;
case "UnusedHindrances": UnusedHindrances += bonus; return;
case "UnusedAdvances": UnusedAdvances += bonus; return;
case "PowerPoints": dice.Choose(PowerGroups).PowerPoints += bonus; return;
case "UnusedPowers": dice.Choose(PowerGroups).UnusedPowers += bonus; return;
}

if (trait.StartsWith("PowerPoints:"))
{
PowerGroups[trait.Substring("PowerPoints:".Length)].PowerPoints += bonus;
return;
}

if (trait.StartsWith("UnusedPowers:"))
{
PowerGroups[trait.Substring("UnusedPowers:".Length)].UnusedPowers += bonus;
return;
}

throw new ArgumentException("Unknown trait " + trait);
get { return 2 + Vigor.HalfScore + Toughness + Armor; }
}

internal Trait GetAttribute(string attribute)
{
switch (attribute)
{
case "Vigor": return Vigor;
case "Smarts": return Smarts;
case "Agility": return Agility;
case "Strength": return Strength;
case "Spirit": return Spirit;
}
throw new ArgumentException("Unknown attribute " + attribute);
}
public int Armor { get { return Get<int>(); } set { Set(value); } }

public int UnusedAdvances { get { return Get<int>(); } set { Set(value); } }
public int UnusedAttributes { get { return Get<int>(); } set { Set(value); } }
public int UnusedEdges { get { return Get<int>(); } set { Set(value); } }
public int UnusedHindrances { get { return Get<int>(); } set { Set(value); } }
public int UnusedIconicEdges { get { return Get<int>(); } set { Set(value); } }
public int UnusedRacialEdges { get { return Get<int>(); } set { Set(value); } }
public int UnusedSkills { get { return Get<int>(); } set { Set(value); } }
public int UnusedSmartSkills { get { return Get<int>(); } set { Set(value); } }
public bool UseReason { get => Get<bool>(); set => Set(value); }
public bool UseStatus { get => Get<bool>(); set => Set(value); }
public bool UseStrain { get => Get<bool>(); set => Set(value); }
public Trait Vigor { get => Get<Trait>(); set => Set(value); }
/// <summary>
/// Determines whether the specified feature has feature.
/// </summary>
Expand Down Expand Up @@ -254,7 +175,78 @@ public bool HasFeature(string feature, bool ignoreRank)
return false;
}

public PowerGroupCollection PowerGroups => GetNew<PowerGroupCollection>();
public void Increment(string trait, Dice dice)
{
Increment(trait, 1, dice);
}

public void Increment(string trait, int bonus, Dice dice)
{
switch (trait)
{
case "Vigor": Vigor += bonus; return;
case "Smarts": Smarts += bonus; return;
case "Agility": Agility += bonus; return;
case "Strength": Strength += bonus; return;
case "Spirit": Spirit += bonus; return;

case "MaxVigor": MaxVigor += bonus; return;
case "MaxSmarts": MaxSmarts += bonus; return;
case "MaxAgility": MaxAgility += bonus; return;
case "MaxStrength": MaxStrength += bonus; return;
case "MaxSpirit": MaxSpirit += bonus; return;

case "Pace": Pace += bonus; return;
case "Running": Running += bonus; return;
case "Charisma": Charisma += bonus; return;
case "Parry": Parry += bonus; return;
case "Toughness": Toughness += bonus; return;
case "Strain": Strain += bonus; return;
case "MaximumStrain": MaximumStrain += bonus; return;
case "Reason": Reason += bonus; return;
case "Status": Status += bonus; return;
case "Size": Size += bonus; return;
case "Armor": Armor += bonus; return;


case "UnusedAttributes": UnusedAttributes += bonus; return;
case "UnusedSkills": UnusedSkills += bonus; return;
case "UnusedSmartSkills": UnusedSmartSkills += bonus; return;
case "UnusedEdges": UnusedEdges += bonus; return;
case "UnusedRacialEdges": UnusedRacialEdges += bonus; return;
case "UnusedHindrances": UnusedHindrances += bonus; return;
case "UnusedAdvances": UnusedAdvances += bonus; return;
case "PowerPoints": dice.Choose(PowerGroups).PowerPoints += bonus; return;
case "UnusedPowers": dice.Choose(PowerGroups).UnusedPowers += bonus; return;
}

if (trait.StartsWith("PowerPoints:"))
{
PowerGroups[trait.Substring("PowerPoints:".Length)].PowerPoints += bonus;
return;
}

if (trait.StartsWith("UnusedPowers:"))
{
PowerGroups[trait.Substring("UnusedPowers:".Length)].UnusedPowers += bonus;
return;
}

throw new ArgumentException("Unknown trait " + trait);
}

internal Trait GetAttribute(string attribute)
{
switch (attribute)
{
case "Vigor": return Vigor;
case "Smarts": return Smarts;
case "Agility": return Agility;
case "Strength": return Strength;
case "Spirit": return Spirit;
}
throw new ArgumentException("Unknown attribute " + attribute);
}
}
}

3 changes: 1 addition & 2 deletions SavageTools/SavageTools.Shared/Characters/Feature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ public class Feature : ChangeTrackingModelBase
{
public string Name { get => Get<string>(); set => Set(value); }

}
}
} }
Loading

0 comments on commit 433f3a0

Please sign in to comment.