Exemplo n.º 1
0
    def process_mob(self, main_task, hero):
        mob_uuid = self.preference_id

        if mob_uuid is not None:

            if  not mobs_storage.has_mob(mob_uuid):
                main_task.comment = 'unknown mob id: %s' % (mob_uuid, )
                self.state = CHOOSE_PREFERENCES_TASK_STATE.UNKNOWN_MOB
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            mob = mobs_storage.get_by_uuid(mob_uuid)

            if not mob.state.is_ENABLED:
                main_task.comment = 'mob %s not in game' % (mob_uuid, )
                self.state = CHOOSE_PREFERENCES_TASK_STATE.MOB_NOT_IN_GAME
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            if hero.level < mob.level:
                main_task.comment = 'hero level < mob level (%d < %d)' % (hero.level, mob.level)
                self.state = CHOOSE_PREFERENCES_TASK_STATE.LARGE_MOB_LEVEL
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

        hero.preferences.set_mob(mobs_storage.get_by_uuid(mob_uuid))

        return POSTPONED_TASK_LOGIC_RESULT.SUCCESS
Exemplo n.º 2
0
    def process_mob(self, main_task, hero):
        mob_uuid = self.preference_id

        if mob_uuid is not None:

            if not mobs_storage.has_mob(mob_uuid):
                main_task.comment = u'unknown mob id: %s' % (mob_uuid, )
                self.state = CHOOSE_PREFERENCES_TASK_STATE.UNKNOWN_MOB
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            mob = mobs_storage.get_by_uuid(mob_uuid)

            if not mob.state.is_ENABLED:
                main_task.comment = u'mob %s not in game' % (mob_uuid, )
                self.state = CHOOSE_PREFERENCES_TASK_STATE.MOB_NOT_IN_GAME
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

            if hero.level < mob.level:
                main_task.comment = u'hero level < mob level (%d < %d)' % (
                    hero.level, mob.level)
                self.state = CHOOSE_PREFERENCES_TASK_STATE.LARGE_MOB_LEVEL
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

        hero.preferences.set_mob(mobs_storage.get_by_uuid(mob_uuid))

        return POSTPONED_TASK_LOGIC_RESULT.SUCCESS
Exemplo n.º 3
0
    def deserialize(cls, data):
        # we do not save abilities and after load, mob can has differen abilities levels
        # if mob record is desabled or deleted, get another random record

        from the_tale.game.mobs.storage import mobs_storage

        record = mobs_storage.get_by_uuid(data['id'])

        level = data['level']

        if record is None or record.state.is_DISABLED:
            record = random.choice(mobs_storage.get_available_mobs_list(level))

        abilities = cls._produce_abilities(record, level)

        return cls(record_id=record.id,
                   level=level,
                   health=data['health'],
                   is_boss=data.get('is_boss', False),
                   abilities=abilities,
                   action_type=actions_relations.ACTION_TYPE(
                       data['action_type']) if 'action_type' in data else
                   actions_relations.ACTION_TYPE.BATTLE_PVE_1X1,
                   terrain=map_relations.TERRAIN(data['terrain'])
                   if 'terrain' in data else map_relations.TERRAIN.PLANE_GRASS)
Exemplo n.º 4
0
    def test_mob_attributes(self):
        MobRecordPrototype.create(uuid='bandit',
                                  level=1,
                                  utg_name=names.generator.get_test_name(name='bandit'),
                                  description='bandint',
                                  abilities=['hit', 'thick', 'slow', 'extra_strong'],
                                  terrains=TERRAIN.records,
                                  type=MOB_TYPE.CIVILIZED,
                                  archetype=game_relations.ARCHETYPE.NEUTRAL,
                                  state=MOB_RECORD_STATE.ENABLED)
        mobs_storage.sync(force=True)

        bandit = MobPrototype(record_id=mobs_storage.get_by_uuid('bandit').id, level=1)

        self.assertEqual(bandit.health_cooficient, 1.025)
        self.assertEqual(bandit.initiative, 0.975)
        self.assertEqual(bandit.damage_modifier, 1.05)
Exemplo n.º 5
0
    def test_mob_attributes(self):
        MobRecordPrototype.create(uuid='bandit',
                                  level=1,
                                  utg_name=names.generator.get_test_name(name='bandit'),
                                  description='bandint',
                                  abilities=['hit', 'thick', 'slow', 'extra_strong'],
                                  terrains=TERRAIN.records,
                                  type=game_relations.BEING_TYPE.CIVILIZED,
                                  archetype=game_relations.ARCHETYPE.NEUTRAL,
                                  state=MOB_RECORD_STATE.ENABLED)
        mobs_storage.sync(force=True)

        bandit = MobPrototype(record_id=mobs_storage.get_by_uuid('bandit').id, level=1)

        self.assertEqual(bandit.health_cooficient, 1.025)
        self.assertEqual(bandit.initiative, 0.975)
        self.assertEqual(bandit.damage_modifier, 1.05)
Exemplo n.º 6
0
    def deserialize(cls, data):
        # we do not save abilities and after load, mob can has differen abilities levels
        # if mob record is desabled or deleted, get another random record

        from the_tale.game.mobs.storage import mobs_storage

        record = mobs_storage.get_by_uuid(data['id'])

        level = data['level']

        if record is None or record.state.is_DISABLED:
            record = random.choice(mobs_storage.get_available_mobs_list(level))

        abilities = cls._produce_abilities(record, level)

        return cls(record_id=record.id,
                   level=level,
                   health=data['health'],
                   is_boss=data.get('is_boss', False),
                   abilities=abilities)
Exemplo n.º 7
0
    def deserialize(cls, data):
        # we do not save abilities and after load, mob can has differen abilities levels
        # if mob record is desabled or deleted, get another random record

        from the_tale.game.mobs.storage import mobs_storage

        record = mobs_storage.get_by_uuid(data['id'])

        level = data['level']

        if record is None or record.state.is_DISABLED:
            record = random.choice(mobs_storage.get_available_mobs_list(level))

        abilities = cls._produce_abilities(record, level)

        return cls(record_id=record.id,
                   level=level,
                   health=data['health'],
                   is_boss=data.get('is_boss', False),
                   abilities=abilities)
Exemplo n.º 8
0
    def deserialize(cls, data):
        # we do not save abilities and after load, mob can has differen abilities levels
        # if mob record is desabled or deleted, get another random record

        from the_tale.game.mobs.storage import mobs_storage

        record = mobs_storage.get_by_uuid(data['id'])

        level = data['level']

        if record is None or record.state.is_DISABLED:
            record = random.choice(mobs_storage.get_available_mobs_list(level))

        abilities = cls._produce_abilities(record, level)

        return cls(record_id=record.id,
                   level=level,
                   health=data['health'],
                   is_boss=data.get('is_boss', False),
                   abilities=abilities,
                   action_type=actions_relations.ACTION_TYPE(data['action_type']) if 'action_type' in data else actions_relations.ACTION_TYPE.BATTLE_PVE_1X1,
                   terrain=map_relations.TERRAIN(data['terrain']) if 'terrain' in data else map_relations.TERRAIN.PLANE_GRASS)