Skip to content

Commit

Permalink
reduce cluttered align "if"s with dict import
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoc committed Nov 13, 2022
1 parent ba2fe35 commit b65b28c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
20 changes: 5 additions & 15 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from sqlalchemy.schema import FetchedValue
from sqlalchemy.orm import relationship
from database import Base, db_session
from mud_secret import IMM_LEVELS
from mud_secret import ALIGNMENTS, IMM_LEVELS
import delta


class Account(Base, UserMixin):
"""Account used to log in to the website and MUD in-game"""
__tablename__ = 'accounts'
Expand Down Expand Up @@ -542,20 +543,9 @@ def is_immortal(self):
@cached_property
def player_alignment(self):
"""Player alignment"""
if self.align <= -1000:
return 'Very Evil'
if self.align > -1000 and self.align <= -500:
return 'Evil'
if self.align > -500 and self.align <= -250:
return 'Slightly Evil'
if self.align > -250 and self.align < 250:
return 'Neutral'
if self.align >= 250 and self.align < 500:
return 'Slightly Good'
if self.align >= 500 and self.align < 1000:
return 'Good'
if self.align >= 1000:
return 'Very Good'
for text, (low, high) in ALIGNMENTS.items():
if self.align >= low and self.align <= high:
return text
return 'Unknown'

@cached_property
Expand Down
25 changes: 18 additions & 7 deletions mud_secret.py.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
"""Various secrets specific to the MUD itself"""

MUD_HOME = '/home/ishar/ishar-mud'
MUD_LIB = f'{MUD_HOME}/lib'
HELPTAB = f'{MUD_LIB}/Misc/helptab'
PODIR = f'{MUD_LIB}/Podir'

ALIGNMENTS = {
'Very Evil': (-1500, -1000),
'Evil': (-1000, -500),
'Slightly Evil': (-500, -250),
'Neutral': (-250, 250),
'Slightly Good': (250, 500),
'Good': (500, 1000),
'Very Good': (1000, 1500)
}

IMM_LEVELS = {
26: 'God',
25: 'Forger',
24: 'Eternal',
23: 'Artisan',
22: 'Immortal',
21: 'Consort'
}
26: 'God',
25: 'Forger',
24: 'Eternal',
23: 'Artisan',
22: 'Immortal',
21: 'Consort'
}

0 comments on commit b65b28c

Please sign in to comment.