Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tijptjik committed Jun 7, 2016
2 parents 68551bf + 022f5a0 commit 5dec2ca
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 48 deletions.
1 change: 1 addition & 0 deletions S06/character-health-fix.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion S06/core/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@


for league in game.leagues:
league.process_episode_results_and_publish()
league.process_episode_results_and_publish()
8 changes: 5 additions & 3 deletions S06/core/house.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def plot_assassination(self, league, missions, target_roster):
"success" : success
}

pprint(damage_potential)
# pprint(damage_potential)

return damage_potential

Expand Down Expand Up @@ -488,7 +488,7 @@ def foil_assassination(self, league, missions, target_roster, damage):
# BOLTON ABILITY

# Chance that an attack on this House backfires and retargets the assassin itself
# Chance is 15% * target's prominence power
# Chance is 15% * target's prominence poewr

v = getattr(league.game.characters[missions['assassination_target_character']], 'prominence')

Expand All @@ -506,8 +506,10 @@ def foil_assassination(self, league, missions, target_roster, damage):
if league.get_player_house_immunity(missions['player']) == new_target_character:
damage_dealt = 0

target_house_name = league.get_player_house(missions['player'])

damage.update({
"target_house" : league.get_player_house(missions['player']),
"target_house" : target_house_name,
"target_character" : new_target_character,
"damage_intended" : damages[violence],
"damage_dealt" : damage_dealt,
Expand Down
89 changes: 45 additions & 44 deletions S06/core/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def __init__(self, name, game):
self.roster_ids = self.collect_player_rosters_ids()
self.rosters = self.collect_player_rosters()

self.character_health = self.collect_character_health()

self.assign_rosters_to_players()


Expand Down Expand Up @@ -71,41 +69,6 @@ def collect_player_rosters_ids(self):
def collect_player_rosters(self):
return {roster_id: roster.values() for roster_id, roster in self.game.rosters.iteritems() if roster_id in self.roster_ids}

def collect_character_health(self):
""" HEALTH FOR ROSTER CHARACTER IN LEAGUE
character_health.
<house_id>.
<character_id> : health
"""

for roster_id, roster in self.rosters.iteritems():

house = self.get_roster_house(roster_id)
key = "{}{}{}".format(self.name, house, self.current_episode)
prev_key = "{}{}{}".format(self.name, house, str(int(self.current_episode)-1))

# GET CHAR_HEALTH FROM PREVIOUS EPISODE AND SET IT AS THE CURRENT
if prev_key in self.game.character_health:

health = self.game.character_health[prev_key]
health.update({"episode" : self.current_episode})

self.game.character_health[key] = health

# IF NO CHAR_HEALTH, GENERATE DEFAULT
else:
health = {
"episode" : self.current_episode,
"house" : house,
"roster" : roster_id,
"health" : dict(zip(roster, [100]*len(roster) ))
}
self.game.character_health[key] = health

self.game.set_character_health(key, health)

return {h['house']: h['health'] for key, h in self.game.character_health.iteritems() if h['roster'] in self.roster_ids}

def get_player(self, uid):
return [p for p in self.players if p.id == uid][0]

Expand All @@ -131,6 +94,9 @@ def get_house_player(self, house):
def get_roster_house(self, rid):
return [p.house.name for p in self.players if p.roster_id == rid][0]

def get_roster_player(self, rid):
return [p for p in self.players if p.roster_id == rid][0]

def get_episode_title(self, epno):
return [e.title for id, e in self.game.episodes.iteritems() if id == str(epno)][0]

Expand All @@ -139,10 +105,44 @@ def get_episode_number(self, epno):


def assign_rosters_to_players(self):
for player in self.players:
""" HEALTH FOR ROSTER CHARACTER IN LEAGUE
character_health.
<house_id>.
<character_id> : health
"""

for roster_id, roster in self.rosters.iteritems():

house = self.get_roster_house(roster_id)
key = "{}{}{}".format(self.name, house, self.current_episode)
prev_key = "{}{}{}".format(self.name, house, str(int(self.current_episode)-1))

# GET CHAR_HEALTH FROM PREVIOUS EPISODE AND SET IT AS THE CURRENT
if prev_key in self.game.character_health:

health = self.game.character_health[prev_key].copy()
health.update({"episode" : self.current_episode})

self.game.character_health[key] = health

# IF NO CHAR_HEALTH, GENERATE DEFAULT
else:
health = {
"episode" : self.current_episode,
"house" : house,
"roster" : roster_id,
"health" : dict(zip(roster, [100]*len(roster) ))
}
self.game.character_health[key] = health

self.game.set_character_health(key, health)

# Assign to player objects
player = self.get_roster_player(roster_id)
player.roster = self.rosters[player.roster_id]
player.character_health = self.character_health[player.house.name]
player.character_health = health['health']
player.roster_prominence = player.get_roster_prominence(self.game.characters)


# Weekly Processes

Expand All @@ -160,7 +160,6 @@ def process_episode_results(self, votes=True, missions=False, analytics=True):
self.score_weekly_episode()
print '*** VOTES COUNTED ***'


if missions:
# DEVELOPER
self.run_weekly_diplomatic_missions()
Expand Down Expand Up @@ -296,9 +295,9 @@ def run_weekly_assassion_missions(self):

murder_print = lambda m : "House {house} assassination of {murder[target_house]}, dealt {murder[damage_dealt]} damage".format(**m)

for murder in murder_set:
if murder['murder']['success']:
pprint(murder_print(murder))
# for murder in murder_set:
# if murder['murder']['success']:
# pprint(murder_print(murder))

# Dock Character Health

Expand Down Expand Up @@ -365,13 +364,15 @@ def process_murder_log(self, murder_set):

mx = murder['murder']

# Update Character Health on Player
self.get_house_player(mx['target_house']).character_health[mx['target_character']] -= mx['damage_dealt']

keys = murder.copy()
keys.update({
'house' : murder['murder']['target_house']
})

# Update Character Health on Game
self.game.update_character_health(keys, murder['murder'])


Expand Down Expand Up @@ -571,7 +572,7 @@ def award_weekly_points(self):
player_roster_award_scores = {}

for award in self.game.awards:

award_score = self.current_episode_score[award]
awarded_points = player.house.award_points(self, self.current_episode, award,
award_score, self.game.characters, player.character_health, player.missions)
Expand Down
Loading

0 comments on commit 5dec2ca

Please sign in to comment.