Skip to content

Commit

Permalink
Added the full list of professions to Professions.txt
Browse files Browse the repository at this point in the history
Started implementation of initial stat distributions.
  Changed level-up of stats to specify a Delta, rather than an absolute value,
   for parallels with skill levelling-up.
  Can modify stat, ask for the points in the potential or the current stat value.
Currently, changing of the potential stat is bugged, to be fixed in next version.
  • Loading branch information
Lunderberg committed Apr 6, 2013
1 parent 1790ce7 commit 518cdef
Show file tree
Hide file tree
Showing 7 changed files with 565 additions and 118 deletions.
42 changes: 30 additions & 12 deletions Character.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,14 @@ def LoadProfession(self,profname,profdict):
self[skill].Costs = costs[:]
except KeyError:
pass
def StatPoints(self,levelled=False):
return sum(st.Points(levelled) for st in self.Stats)
def StatPointsAllowed(self,levelled=False):
level = self.GetMisc('Level') + (1 if levelled else 0)
return 55+12*level
def StatPoints(self,levelled=False,potl=False):
return sum(st.Points(levelled,potl) for st in self.Stats)
def StatPointsAllowed(self,level=None,potl=False):
if potl:
return 355
else:
level = self.GetMisc('Level') if level is None else level
return 55 if level==0 else 12
def DPspent(self):
return sum(sk.DPspent() for sk in self.Skills)
def DPallowed(self):
Expand Down Expand Up @@ -222,8 +225,11 @@ def Value(self):
return 0 if self._value is None else self._value
@Value.setter
def Value(self,val):
self._value = val
self.Changed()
if self.IsValid(val):
self._value = val
self.Changed()
def IsValid(self,val):
return True
@property
def Delta(self):
return self._delta
Expand Down Expand Up @@ -371,16 +377,28 @@ def Max(self):
except:
pass
else:
return 100
return 50
@Max.setter
def Max(self,val):
self.Options = [opt for opt in self.Options if opt[3:]!='Max']
self.Options.append('Max' + '{0:+d}'.format(val))
self.Changed(False)
def SelfBonus(self,asker=None,levelled=False):
return 0 if self.NoBonus else _statBonuses(self.Value + (self.Delta if levelled else 0))
def Points(self,levelled=False):
return 0 if self.NoBonus else _statBonuses(self.Value + (self.Delta if levelled else 0),item=1)
def IsValid(self,val):
return 1 <= val <= 100
def SelfBonus(self,asker=None,levelled=False,potl=False):
if self.NoBonus:
return 0
elif potl:
return _statBonuses(self.Max)
else:
return _statBonuses(self.Value + (self.Delta if levelled else 0))
def Points(self,levelled=False,potl=False):
if self.NoBonus:
return 0
elif potl:
return _statBonuses(self.Max,item=1)
else:
return _statBonuses(self.Value + (self.Delta if levelled else 0),item=1)

class Resistance(Value):
Type = 'Resistance'
Expand Down
31 changes: 22 additions & 9 deletions MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ def __init__(self):
self.b.get_object('statView').connect('cursor-changed',self.FromStatSelected)
self.b.get_object('statNameBox').connect('changed',self.FromActiveStatNameChange)
self.b.get_object('statCurrentBox').connect('changed',self.FromActiveStatCurrentChange)
self.b.get_object('statPotentialBox').connect('changed',self.FromActiveStatPotentialChange)
self.b.get_object('statDescriptionBox').get_buffer().connect('changed',self.FromActiveStatDescriptionChange)
self.b.get_object('postLevelStatValue').connect('changed',self.FromActiveStatLevellingChange)
self.b.get_object('postLevelStatValue').connect('value-changed',self.FromActiveStatLevellingChange)
self.b.get_object('levellingStatGain').connect('changed',self.FromActiveStatLevellingChange)
self.b.get_object('levellingStatGain').connect('value-changed',self.FromActiveStatLevellingChange)

#Skill modifications
self.activeSkill = None
Expand Down Expand Up @@ -332,10 +333,10 @@ def UpdateActiveStat(self,stat):
self.b.get_object('statBonusLabel').set_text(str(stat.Bonus()))
self.b.get_object('statPotentialBox').set_text(str(stat.Max))
better_set_text(self.b.get_object('statDescriptionBox').get_buffer(),stat.Description)
adj = self.b.get_object('postLevelStatValue')
adj.set_value(stat.Value + stat.Delta)
adj.set_lower(stat.Min)
adj.set_upper(stat.Max)
adj = self.b.get_object('levellingStatGain')
adj.set_value(stat.Delta)
adj.set_lower(0)
adj.set_upper(stat.Max-stat.Value)
self.b.get_object('postLevelStatBonus').set_text(str(stat.SelfBonus(levelled=True)))
def UpdateActiveSkill(self,skill):
self.b.get_object('skillNameBox').set_text(skill.Name)
Expand Down Expand Up @@ -445,8 +446,11 @@ def OnStatChange(self,stat):
self.UpdateStatOverview(stat)
if stat is self.activeStat and stat is not None:
self.UpdateActiveStat(stat)
self.b.get_object('SPspentLabel').set_text('Stat Points Spent: {0}/{1}'.format(
self.char.StatPoints(levelled=True), self.char.StatPointsAllowed(levelled=True)))
for widname in ['SPspentLabel','initSPspent']:
self.b.get_object(widname).set_text('Stat Points Spent: {0}/{1}'.format(
self.char.StatPoints(levelled=True)-self.char.StatPoints(), self.char.StatPointsAllowed()))
self.b.get_object('potlSPspent').set_text("Pot'l Stat Points Spent: {0}/{1}".format(
self.char.StatPoints(potl=True), self.char.StatPointsAllowed(potl=True)))
def FromSkillSelected(self,*args):
selection = self.skillView.get_selection()
model,skIter = selection.get_selected()
Expand Down Expand Up @@ -523,16 +527,25 @@ def FromActiveStatNameChange(self,widget):
def FromActiveStatCurrentChange(self,widget):
if self.activeStat is not None:
try:
print "Changing stat to ",widget.get_text()
self.activeStat.Value = int(widget.get_text())
except ValueError:
pass
print "Done Changing"
def FromActiveStatPotentialChange(self,widget):
if self.activeStat is not None:
print "box text ", widget.get_text()
try:
self.activeStat.Max = int(widget.get_text())
except ValueError:
pass
def FromActiveStatDescriptionChange(self,widget):
if self.activeStat is not None:
text = widget.get_text(widget.get_start_iter(),widget.get_end_iter())
self.activeStat.Description = text
def FromActiveStatLevellingChange(self,widget):
if self.activeStat is not None:
self.activeStat.Delta = int(widget.get_value())-self.activeStat.Value
self.activeStat.Delta = int(widget.get_value())
def FromActiveSkillNameChange(self,widget):
if self.activeSkill is not None:
self.activeSkill.Name = self.b.get_object('skillNameBox').get_text()
Expand Down
6 changes: 4 additions & 2 deletions Professions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import re
from collections import OrderedDict

def LoadProfessions(filename):
"""
Expand All @@ -10,7 +11,7 @@ def LoadProfessions(filename):
"""
with open(filename) as f:
text = f.read()
profs = {}
profs = OrderedDict()
#Strip out comments.
text = re.sub(r'(^|[^\\])#.*',r'',text)
for profMatch in re.finditer(r'(\S[^{}]*?)\s*'
Expand All @@ -28,4 +29,5 @@ def LoadProfessions(filename):

if __name__=='__main__':
import pprint
pprint.pprint(LoadProfessions('tables/Professions.txt'))
LoadProfessions('tables/Professions.txt')

20 changes: 16 additions & 4 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ Implement StatBonus, ParentBonus, ItemBonus in Value

Have Ctrl-N,O,S start New, Open, and Save commands.

Add potential stat to the save format and to the Character.Stat object.
Added as "Max+Num" option.
Still need to add GUI options to change this.

Removing a bonus from an item does not update skills that were children, but are no longer.
Ex. "Dagger+5, Linguistics-2" becomes "Dagger+5" would not remove the -2 from Linguistics.
Fix this.
Expand All @@ -49,3 +45,19 @@ Experiment with having text columns update only on losing focus
Add a "Disabled" parameter to items,
allowing for item-bonuses to be temporarily disabled.
This could be used, for example, if an item is broken, but can be repaired.

Improve GUI-backend communication.
Currently, the reading of values from the backend can cause additional backend changes,
such as when reloading the active stat.
This can cause infinite loops that become hard to diagnose.
To fix this, should make two big changes.
1. Have EventHandler collect the signals to be run,
but not call them until an "Execute" function is called.
This will allow for delayed updating of the GUI.
2. Have a MainWindow.Update() function, to be called when the GUI is to be updated from the backend.
Should first disable all the signals from the GUI.
object.handler_block(handler_id)
Then, should call self.char.Events.Executes() (Probably through a self.char.Update())
Finally, re-enable the signals from the GUI.
object.handler_unblock(handler_id)
This way, the GUI will only be updated at specified times.
Loading

0 comments on commit 518cdef

Please sign in to comment.