Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
reset shops timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Arzaroth Lekva committed Dec 30, 2014
1 parent b5a6bac commit c83d24a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CelestiaSunrise.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
PRGM = os.path.basename(__file__)
except NameError:
PRGM = os.path.basename(sys.argv[0])
VERSION = "0.8.0a"
VERSION = "0.8.1a"

__doc__ = """
{prgm} {ver}
Expand Down
2 changes: 2 additions & 0 deletions src/ponyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def do_set(self, args):
set pony (level|shards|next_game) <value> <pony_id>...
set pony reset_game_timer <pony_id>...
set zones clear [clearables|foes]
set zones reset_shops_timer
set zone clear [clearables|foes] <zone_id>...
set zone reset_shops_timer <zone_id>...
Arguments:
currency_id Id of a currency. Can be retrieved with "show currencies".
Expand Down
15 changes: 9 additions & 6 deletions src/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ def set_pony(xml_handle, args):
print(str(e))

def _process_set_zone(xml_handle, zone, args):
if args['clearables']:
zone.clearable_items.clear()
elif args['foes']:
zone.foes.clear()
else:
zone.clear()
if args['clear']:
if args['clearables']:
zone.clearable_items.clear()
elif args['foes']:
zone.foes.clear()
else:
zone.clear()
elif args['reset_shops_timer']:
zone.shops.reset_shops_timer()

def set_zones(xml_handle, args):
for zone in xml_handle.zones.values():
Expand Down
24 changes: 22 additions & 2 deletions src/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from collections import defaultdict
from src.defaultordereddict import DefaultOrderedDict

ZERO = "0.000000"

class Inventory(object):
def __init__(self, tag):
self._tag = tag
Expand Down Expand Up @@ -199,7 +201,7 @@ def shard_down(self):
self.shards = 0

def reset_game_timer(self):
self._minigametag["@NextPlayTime"] = "0.000000"
self._minigametag["@NextPlayTime"] = ZERO


class Currency(object):
Expand Down Expand Up @@ -262,12 +264,30 @@ def __init__(self, ID, name, tag):
self.name = name


class Shops(object):
def __init__(self, tag):
shops = [] if tag is None else tag['Object']
if type(shops) != list:
tag['Objects'] = [tag['Object']]
shops = tag['Objects']
self._shops = [shop for shop in shops if 'ShopProduction' in shop]

def reset_shops_timer(self):
for shop in self._shops:
shop['ShopProduction']['@TimeA'] = ZERO
shop['ShopProduction']['@TimeB'] = ZERO

def __len__(self):
return len(self._shops)


class Zone(object):
def __init__(self, ID, name, clearables, foes):
def __init__(self, ID, name, clearables, foes, shops):
self.ID = ID
self.name = name
self.clearable_items = clearables
self.foes = foes
self.shops = shops

def cleared(self):
return self.clearable_items.cleared() and self.foes.cleared()
Expand Down
5 changes: 3 additions & 2 deletions src/xmlhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from src.defaultordereddict import DefaultOrderedDict
from src.utility import (Pony, Inventory,
Currency, Clearables,
Foes, Zone)
Foes, Zone, Shops)

def remove_parent(xml_data):
return xml_data.replace('(', '_x0028_').replace(')', '_x0029_')
Expand Down Expand Up @@ -121,10 +121,11 @@ def _get_zones(self):
foes = Foes(zone_spec["foes"]["ID"],
zone_spec["foes"]["name"],
gameobjects)
shops = Shops(gameobjects['Pony_House_Objects'])
zones[mapzone["@ID"]] = Zone(mapzone["@ID"],
zone_spec["name"],
clearables,
foes)
foes, shops)
return zones

def _get_actions(self):
Expand Down
27 changes: 22 additions & 5 deletions src/zonesframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,40 @@
from __future__ import print_function, absolute_import, unicode_literals
try:
# py3
from tkinter import Frame, Checkbutton, BooleanVar, StringVar
from tkinter import Frame, Checkbutton, Label, BooleanVar, StringVar
from tkinter.constants import N, S, E, W, NSEW
except ImportError:
# py2
from Tkinter import Frame, Checkbutton, BooleanVar, StringVar
from Tkinter import Frame, Checkbutton, Label, BooleanVar, StringVar
from Tkconstants import N, S, E, W, NSEW

class ZoneFrame(object):

def __init__(self, parent, zone, offset):
def __init__(self, parent, zone, offset, reset_offset):
self.parent = parent
self.zone = zone

self._clearables_checked = BooleanVar(self.parent, False)
self._foes_checked = BooleanVar(self.parent, False)
self._reset_checked = BooleanVar(self.parent, False)
self._clearables_text = StringVar(self.parent)
self._foes_text = StringVar(self.parent)
self._reset_text = StringVar(self.parent)
self.update()
self._clearables_box = Checkbutton(self.parent,
textvariable=self._clearables_text,
variable=self._clearables_checked)
self._foes_box = Checkbutton(self.parent,
textvariable=self._foes_text,
variable=self._foes_checked)
self._reset_box = Checkbutton(self.parent,
textvariable=self._reset_text,
variable=self._reset_checked)

options = dict(sticky=W, padx=3, pady=2)
self._clearables_box.grid(row=(offset * 2), column=0, **options)
self._foes_box.grid(row=(offset * 2) + 1, column=0, **options)

self._reset_box.grid(row=reset_offset + offset, column=0, **options)

def update(self):
self._clearables_text.set("Remove Clearables Objects from {} ({} remaining)"
Expand All @@ -47,6 +52,10 @@ def update(self):
.format(self.zone.foes.name,
self.zone.name,
len(self.zone.foes)))
self._reset_text.set("Reset shops timer for {} ({} shop{})"
.format(self.zone.name,
len(self.zone.shops),
"s" if len(self.zone.shops) > 1 else ""))

@property
def clearables_checked(self):
Expand All @@ -56,6 +65,10 @@ def clearables_checked(self):
def foes_checked(self):
return self._foes_checked.get()

@property
def reset_checked(self):
return self._reset_checked.get()


class ZonesFrame(Frame):

Expand All @@ -64,13 +77,17 @@ def __init__(self, parent, xml_handle):

self._xml_handle = xml_handle
self._zones = {}
reset_offset = len(self._xml_handle.zones) * 2
Label(self).grid(row=reset_offset, column=0)
for n, (ID, zone) in enumerate(self._xml_handle.zones.items()):
self._zones[ID] = ZoneFrame(self, zone, n)
self._zones[ID] = ZoneFrame(self, zone, n, reset_offset + 1)

def commit(self):
for ID, zone in self._xml_handle.zones.items():
if self._zones[ID].clearables_checked:
zone.clearable_items.clear()
if self._zones[ID].foes_checked:
zone.foes.clear()
if self._zones[ID].reset_checked:
zone.shops.reset_shops_timer()
self._zones[ID].update()

0 comments on commit c83d24a

Please sign in to comment.