本文整理汇总了Python中the_tale.game.prototypes.TimePrototype类的典型用法代码示例。如果您正苦于以下问题:Python TimePrototype类的具体用法?Python TimePrototype怎么用?Python TimePrototype使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimePrototype类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_push_power
def test_push_power(self):
self.place.push_power(0, 10)
self.assertEqual(self.place.power, 10)
TimePrototype.get_current_time().increment_turn()
self.place.push_power(1, 1)
self.assertEqual(self.place.power,
1 + 10*float(places_settings.POWER_HISTORY_LENGTH-1)/places_settings.POWER_HISTORY_LENGTH)
TimePrototype(places_settings.POWER_HISTORY_LENGTH-1).save()
self.place.push_power(places_settings.POWER_HISTORY_LENGTH-1, 100)
self.assertEqual(self.place.power,
100 + 10*1.0/places_settings.POWER_HISTORY_LENGTH + 2.0/places_settings.POWER_HISTORY_LENGTH)
TimePrototype(places_settings.POWER_HISTORY_LENGTH).save()
self.place.push_power(places_settings.POWER_HISTORY_LENGTH, 1000)
self.assertEqual(self.place.power,
1000 + 100*float(places_settings.POWER_HISTORY_LENGTH-1)/places_settings.POWER_HISTORY_LENGTH + 1.0/places_settings.POWER_HISTORY_LENGTH)
TimePrototype(places_settings.POWER_HISTORY_LENGTH+1).save()
self.place.push_power(places_settings.POWER_HISTORY_LENGTH+1, 10000)
self.assertEqual(self.place.power,
10000 +
1000*float(places_settings.POWER_HISTORY_LENGTH-1)/places_settings.POWER_HISTORY_LENGTH +
100*float(places_settings.POWER_HISTORY_LENGTH-2)/places_settings.POWER_HISTORY_LENGTH)
TimePrototype(places_settings.POWER_HISTORY_LENGTH+2).save()
self.place.push_power(places_settings.POWER_HISTORY_LENGTH+2, 100000)
self.assertEqual(round(self.place.power, 5),
round(100000 +
10000*float(places_settings.POWER_HISTORY_LENGTH-1)/places_settings.POWER_HISTORY_LENGTH +
1000*float(places_settings.POWER_HISTORY_LENGTH-2)/places_settings.POWER_HISTORY_LENGTH +
100*float(places_settings.POWER_HISTORY_LENGTH-3)/places_settings.POWER_HISTORY_LENGTH, 5) )
示例2: create_person
def create_person(place, race, type, utg_name, gender, personality_cosmetic=None, personality_practical=None):
if personality_cosmetic is None:
personality_cosmetic = relations.PERSONALITY_COSMETIC.random()
if personality_practical is None:
personality_practical = relations.PERSONALITY_PRACTICAL.random()
person = objects.Person(
id=None,
created_at_turn=TimePrototype.get_current_turn_number(),
updated_at_turn=TimePrototype.get_current_turn_number(),
updated_at=datetime.datetime.now(),
place_id=place.id,
gender=gender,
race=race,
type=type,
attrs=attributes.Attributes(),
personality_cosmetic=personality_cosmetic,
personality_practical=personality_practical,
politic_power=PersonPoliticPower.create(),
utg_name=utg_name,
job=PersonJob.create(normal_power=NORMAL_PERSON_JOB_POWER),
moved_at_turn=TimePrototype.get_current_turn_number(),
)
person.refresh_attributes()
place.refresh_attributes()
save_person(person, new=True)
return person
示例3: test_sync_data__power_from_bonuses_2
def test_sync_data__power_from_bonuses_2(self):
person_1 = self.p1.persons[0]
self.assertEqual(self.p1.power, 0)
self.assertEqual(person_1.power, 0)
person_1.push_power(TimePrototype.get_current_turn_number(), 10000)
self.p1.push_power(TimePrototype.get_current_turn_number(), 10000)
self.worker.process_change_power(
person_id=person_1.id, power_delta=-1000, place_id=None, positive_bonus=0, negative_bonus=0
)
self.worker.sync_data()
self.assertEqual(self.p1.power, 10000 - 1000 * 2 * 1.5)
self.assertEqual(person_1.power, 10000 - 1000 * 2)
self.worker.process_change_power(
place_id=self.p1.id, power_delta=100, person_id=None, positive_bonus=0, negative_bonus=0
)
self.worker.sync_data()
self.assertEqual(self.p1.power, 10000 - 1000 * 2 * 1.5 + 100 * 1.25)
self.assertEqual(person_1.power, 10000 - 1000 * 2)
示例4: setUp
def setUp(self):
super(TestPrototypeEnd, self).setUp()
bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator.get_test_name('new_name_1'))
self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted')
self.bill.state = relations.BILL_STATE.ACCEPTED
TimePrototype.get_current_time().increment_turn()
示例5: create_place
def create_place(self, x, y, size, roads_to, persons=(), name_forms=None, is_frontier=False): # pylint: disable=R0914
place_power = int(max(place.power for place in places_storage.all()) * float(size) / places_settings.MAX_SIZE)
place_power_steps = int(places_settings.POWER_HISTORY_LENGTH / c.MAP_SYNC_TIME)
place_power_per_step = (place_power / place_power_steps) + 1
place = PlacePrototype.create( x=x,
y=y,
utg_name=name_forms.word,
is_frontier=is_frontier,
size=size)
initial_turn = TimePrototype.get_current_turn_number() - places_settings.POWER_HISTORY_LENGTH
for i in xrange(place_power_steps):
place.push_power(int(initial_turn+i*c.MAP_SYNC_TIME), int(place_power_per_step))
for person_name_forms, power_percent, race, gender, tp in persons:
person = PersonPrototype.create(place=place,
race=race,
gender=gender,
tp=tp,
name_forms=person_name_forms)
person_power = place_power * power_percent
person_power_steps = int(persons_conf.settings.POWER_HISTORY_LENGTH / c.MAP_SYNC_TIME)
person_power_per_step = (person_power / person_power_steps) + 1
initial_turn = TimePrototype.get_current_turn_number() - persons_conf.settings.POWER_HISTORY_LENGTH
for i in xrange(person_power_steps):
person.push_power(int(initial_turn+i*c.MAP_SYNC_TIME), int(person_power_per_step))
person.save()
place.sync_persons(force_add=True)
power_delta = self.INITIAL_PERSON_POWER
for person in place.persons:
person.fill_power_evenly(power_delta)
person.save()
power_delta /= 2
place.sync_race()
place.save()
for destination in roads_to:
Road.objects.create(point_1=place._model, point_2=destination._model)
persons_storage.update_version()
places_storage.update_version()
roads_storage.update_version()
persons_storage.refresh()
places_storage.refresh()
roads_storage.refresh()
return place
示例6: test_increment_turn
def test_increment_turn(self):
time = TimePrototype.get_current_time()
self.assertEqual(time.turn_number, 0)
time.increment_turn()
self.assertEqual(time.turn_number, 1)
time.save()
time = TimePrototype.get_current_time()
self.assertEqual(time.turn_number, 1)
示例7: test_creation
def test_creation(self):
Setting.objects.all().delete()
settings.refresh()
settings_number = Setting.objects.all().count()
time = TimePrototype.get_current_time()
self.assertEqual(time.turn_number, 0)
self.assertEqual(Setting.objects.all().count(), settings_number+1)
time = TimePrototype.get_current_time()
self.assertEqual(time.turn_number, 0)
self.assertEqual(Setting.objects.all().count(), settings_number+1)
示例8: test_move_out_game
def test_move_out_game(self):
self.assertEqual(self.person.place.persons_changed_at_turn, self.persons_changed_at_turn)
TimePrototype.get_current_time().increment_turn()
current_time = datetime.datetime.now()
self.assertTrue(self.person.out_game_at < current_time)
self.assertEqual(self.person.state, PERSON_STATE.IN_GAME)
self.person.move_out_game()
self.assertTrue(self.person.out_game_at > current_time)
self.assertEqual(self.person.state, PERSON_STATE.OUT_GAME)
self.assertEqual(self.person.place.persons_changed_at_turn, TimePrototype.get_current_turn_number())
示例9: test_full__double_energy
def test_full__double_energy(self):
self.hero.change_energy(-self.hero.energy)
current_time = TimePrototype.get_current_time()
while len(self.hero.actions.actions_list) != 1:
self.storage.process_turn(continue_steps_if_needed=False)
current_time.increment_turn()
self.assertTrue(self.action_idl.leader)
self.assertEqual(self.hero.energy, self.hero.preferences.energy_regeneration_type.amount * 2)
self.assertEqual(self.hero.need_regenerate_energy, False)
self.assertEqual(self.hero.last_energy_regeneration_at_turn, TimePrototype.get_current_turn_number()-1)
self.storage._test_save()
示例10: test_user_form__move_delay
def test_user_form__move_delay(self):
data = {'caption': 'caption-caption',
'rationale': 'rationale',
'chronicle_on_accepted': 'chronicle-on-accepted',
'person': self.person_2.id,
'new_place': self.place3.id}
form = self.bill.data.get_user_form_update(post=data, owner_id=self.account.id)
self.assertFalse(form.is_valid())
TimePrototype.get_current_time().increment_turn()
form = self.bill.data.get_user_form_update(post=data, owner_id=self.account.id)
self.assertTrue(form.is_valid())
示例11: test_not_enough_voices_percents
def test_not_enough_voices_percents(self):
current_time = TimePrototype.get_current_time()
current_time.increment_turn()
current_time.increment_turn()
VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.REFRAINED)
self.assertEqual(Post.objects.all().count(), 1)
with self.check_not_changed(lambda: self.place1.attrs.stability):
with mock.patch('the_tale.accounts.workers.accounts_manager.Worker.cmd_run_account_method') as cmd_run_account_method:
self.assertFalse(self.bill.apply())
self.assertEqual(cmd_run_account_method.call_count, 0)
self.assertTrue(self.bill.state.is_REJECTED)
self.assertEqual(Post.objects.all().count(), 2)
bill = BillPrototype.get_by_id(self.bill.id)
self.assertTrue(bill.state.is_REJECTED)
places_storage.places.sync(force=True)
self.place1.refresh_attributes()
self.assertEqual(bill.applyed_at_turn, current_time.turn_number)
self.check_place(self.place1.id, self.place1.name, self.place1.utg_name.forms)
示例12: create
def create(cls, owner, caption, rationale, bill, chronicle_on_accepted):
model = Bill.objects.create(owner=owner._model,
type=bill.type,
caption=caption,
rationale=rationale,
created_at_turn=TimePrototype.get_current_turn_number(),
technical_data=s11n.to_json(bill.serialize()),
state=BILL_STATE.VOTING,
chronicle_on_accepted=chronicle_on_accepted,
votes_for=1) # author always wote for bill
bill_prototype = cls(model)
text = u'Обсуждение [url="%s%s"]закона[/url]' % (project_settings.SITE_URL,
reverse('game:bills:show', args=[model.id]) )
thread = ThreadPrototype.create(SubCategoryPrototype.get_by_uid(bills_settings.FORUM_CATEGORY_UID),
caption=caption,
author=get_system_user(),
text=bill_prototype.bill_info_text(text),
technical=True,
markup_method=MARKUP_METHOD.POSTMARKUP)
model.forum_thread = thread._model
model.save()
ActorPrototype.update_actors(bill_prototype, bill_prototype.data.actors)
VotePrototype.create(owner, bill_prototype, VOTE_TYPE.FOR)
signals.bill_created.send(sender=cls, bill=bill_prototype)
return bill_prototype
示例13: add_power_evenly
def add_power_evenly(self, delta):
cells_number = len(self.power_points)
turn_number = TimePrototype.get_current_turn_number()
self.power_points[:] = [ (turn, value+delta/cells_number / (1 - float(turn_number- turn) / history_length))
for turn, value in self.power_points ]
示例14: create
def create(cls, person, utg_name):
from the_tale.game.places import storage
building = storage.buildings.get_by_person_id(person.id)
if building:
return building
# remove any destroyed buildings for person
cls._model_class.objects.filter(person_id=person.id).delete()
x, y = random.choice(list(cls.get_available_positions(person.place.x, person.place.y)))
model = models.Building.objects.create(x=x,
y=y,
data=s11n.to_json({'name': utg_name.serialize()}),
place_id=person.place_id,
person_id=person.id,
state=relations.BUILDING_STATE.WORKING,
created_at_turn=TimePrototype.get_current_turn_number(),
type=person.type.building_type)
prototype = cls(model=model)
storage.buildings.add_item(prototype.id, prototype)
storage.buildings.update_version()
return prototype
示例15: update
def update(self, text):
self._model.text = text
self._model.updated_at_turn = TimePrototype.get_current_turn_number()
self.save()
self.thread.update()
self.thread.subcategory.update()