コード例 #1
0
ファイル: block.py プロジェクト: IlyaFaer/ForwardOnlyGame
    def _gen_env_mods(self, vertices):
        """Randomly select and arrange environment models.

        Args:
            vertices (list): Vertices of the terrain model.

        Returns:
            list:
                Lists in which the first element is an environment
                model name, and the second is its position.
        """
        models = []
        et_suf = "et_" if self.enemy_territory else ""

        for models_conf in LOCATION_CONF[et_suf + "with_quantity"]:
            for _ in range(random.randint(*models_conf["quantity"])):
                models.append((
                    random.choice(models_conf["models"]),
                    take_random(vertices[models_conf["square"]]),
                ))
        for models_conf in LOCATION_CONF[et_suf + "with_chance"]:
            if chance(models_conf["chance"]):
                models.append((
                    random.choice(models_conf["models"]),
                    take_random(vertices[models_conf["square"]]),
                ))
        return models
コード例 #2
0
ファイル: scenario.py プロジェクト: IlyaFaer/ForwardOnlyGame
 def do_medicine_save(self):
     """Do save with medicines effect of Chapter 9."""
     if base.resource("medicine_boxes"):  # noqa: F821
         base.plus_resource("medicine_boxes", -1)  # noqa: F821
     else:
         chars = list(base.team.chars.values())  # noqa: F821
         if chars:
             take_random(chars).energy -= 40
コード例 #3
0
ファイル: scenario.py プロジェクト: IlyaFaer/ForwardOnlyGame
    def do_transfusion_effect(self):
        """Do blood transfusion effect of Chapter 9."""
        char = None
        chars = list(base.team.chars.values())  # noqa: F821

        if chars:
            char = take_random(chars)
            char.health -= 30

        if chars:
            take_random(chars).health -= 30
        elif char:
            char.health -= 30
コード例 #4
0
    def _gen_new_traits(self):
        """Generate new traits on praise.

        One of these traits player can choose
        to add to the character's traits list.
        """
        if base.team.cohesion < 5:  # noqa: F821
            return

        char = self._char_chooser.chosen_item

        pos_traits = list(base.labels.TRAIT_DESC.keys())  # noqa: F821
        for trait in char.traits + char.disabled_traits:
            pos_traits.remove(trait)

        for index in range(3):
            new_trait = take_random(pos_traits)
            self._new_traits[index][0]["text"] = new_trait
            self._new_traits[index][0]["text_fg"] = SILVER_COL
            self._new_traits[index][1][
                "text"] = base.labels.TRAIT_DESC[  # noqa: F821
                    new_trait]
            self._new_traits[index][1]["text_fg"] = SILVER_COL

        base.team.spend_cohesion(4)  # noqa: F821
コード例 #5
0
    def __init__(self, id_, class_, class_data, model, y_positions, enemy_handler):
        Unit.__init__(self, "enemy_" + str(id_), class_, class_data)

        self.transport_snd = None
        self._move_int = None
        self._rb_node = None
        self._tooltip = "Skinhead - " + self.class_

        self._y_positions = y_positions
        self._y_pos = take_random(self._y_positions)

        self._x_range = (-0.3, 0.4) if self.class_data["part"] == "side" else (0.6, 1.3)

        self.node = render.attachNewNode(self.id + "_node")  # noqa: F821
        self.node.setPos(self._io_dist, -7, 0)

        self.model = model
        self.model.pose("ride", 1)
        self.model.reparentTo(self.node)

        # organize movement and aiming tasks
        time_to_overtake = random.randint(33, 50)

        self._move(time_to_overtake, (self._y_pos, random.uniform(*self._x_range), 0))
        taskMgr.doMethodLater(  # noqa: F821
            time_to_overtake + 2, self._float_move, self.id + "_float_move"
        )
コード例 #6
0
ファイル: __init__.py プロジェクト: IlyaFaer/ForwardOnlyGame
    def explode_bomb(self, x_coor, y_coor):
        """Explode a bomb on the Train.

        Args:
            x_coor (float): X coordinate of explosion.
            y_coor (float): Y coordinate of explosion.
        """
        if not self._bomb_explosions:
            return

        explosion = take_random(self._bomb_explosions)
        explosion.setPos(x_coor, y_coor, 0.155)
        explosion.play()

        taskMgr.doMethodLater(  # noqa: F821
            2.55,
            self._bomb_explosions.append,
            "return_bomb_explosion_effect",
            extraArgs=[explosion],
        )
        self.durability -= 4

        if y_coor < -0.1:  # too far from characters
            return

        for char in self.parts[
                "part_left" if x_coor < 0 else "part_right"].chars:
            if abs(char.model.getY() - y_coor) < 0.11:
                char.get_damage(4)
                char.get_stunned()
コード例 #7
0
ファイル: __init__.py プロジェクト: IlyaFaer/ForwardOnlyGame
    def get_shot(self, right_side):
        """Play a particle effect of getting a shot.

        Args:
            right_side (bool): True if the shot came to the right part.
        """

        if self._shot_sparks:
            shot = take_random(self._shot_sparks)

            if self._armor_plate and (
                (self._armor_plate.cur_position == "left" and not right_side)
                    or
                (self._armor_plate.cur_position == "right" and right_side)):
                x, y_range, z_range = random.choice(PLATE_SHOT_COORS)
            else:
                x, y_range, z_range = random.choice(SHOT_COORS)

            if not right_side:
                x = -x

            shot.setPos(x, random.uniform(*y_range), random.uniform(*z_range))
            shot.start(self.model, self.model)
            shot.softStart()

            taskMgr.doMethodLater(  # noqa: F821
                0.2,
                self._stop_shot_effect,
                "stop_shot_effect",
                extraArgs=[shot])
コード例 #8
0
ファイル: block.py プロジェクト: IlyaFaer/ForwardOnlyGame
    def _gen_surface(self, side):
        """Generate a terrain block.

        Randomly choose one of the terrain blocks proper for this
        rails block. Randomly rotate it. Use special terrain blocks
        for enemy territory.

        Args:
            side (str):
                Side of the terrain block, relatively to the railway.

        Returns:
            str, int: Terrain model name, angle.
        """
        if self.enemy_territory:
            return address("surface_en1"), random.choice(ANGLES)

        if self.is_city:
            return address("surface_with_" + side +
                           "_city"), 180 if side == "r" else 0

        if side == self._station_side:
            surface = address(take_random(
                base.world.stations_pool))  # noqa: F821
            return surface, (180 if side == "r" else 0)

        surface = address(random.choice(SURFACES[self.name]))
        if self.name == "direct":
            return surface, random.choice(ANGLES)

        return surface, 0
コード例 #9
0
    def _jump_and_brake(self, task):
        """Jump over the railway and drop a brake shoe."""
        if not self._brakes or self.current_part is None:
            return task.done

        for char in base.world.enemy.active_units.values():  # noqa: F821
            # if someone is jumping now, don't jump
            if (type(char) == BrakeThrower and char.id != self.id
                    and char.is_jumping) or (base.train.l_brake and
                                             base.train.r_brake  # noqa: F821
                                             ):
                return task.again

        y_target = round(abs(self._y_pos) - 0.55, 2)
        if self._y_pos < 0:
            y_target = -y_target

        if y_target not in self._y_positions:
            return task.again

        self._y_positions.remove(y_target)

        self.is_jumping = True
        self._stop_tasks("_float_move")
        self._move_int.pause()

        taskMgr.doMethodLater(  # noqa: F821
            0.15,
            self._jump_snd.play,
            self.id + "_jump_sound",
            extraArgs=[])
        taskMgr.doMethodLater(  # noqa: F821
            1.5,
            self._fall_snd.play,
            self.id + "_fall_sound",
            extraArgs=[])
        taskMgr.doMethodLater(  # noqa: F821
            1,
            self._drop_brake,
            self.id + "_drop_brake",
            extraArgs=[take_random(self._brakes)],
        )
        self._jump_int = Sequence(
            MopathInterval(
                self._r_mopath if self._y_pos < 0 else self._l_mopath,
                self.model,
                duration=2.5,
                name=self.id + "_low_jump",
                blendType="easeOut",
            ),
            Func(self._finish_jump),
        )
        self._jump_int.start()

        self._y_positions.append(self._y_pos)
        self._y_pos = y_target
コード例 #10
0
ファイル: character.py プロジェクト: IlyaFaer/ForwardOnlyGame
    def __init__(self, id_, name, class_, sex, team, desc=None):
        Unit.__init__(
            self, "character_" + str(id_), class_, CLASSES[sex + "_" + class_]
        )
        Shooter.__init__(self)

        self._team = team
        self._current_pos = None
        self._current_anim = None
        self._idle_seq = None
        self._cohesion_ball = None
        self._is_stunned = False
        self._is_stimulated = False
        self._health_bar = None

        self.inhale = 15
        self.damage_range = [5, 8]
        self.clear_damage = [5, 8]
        self.effects = {}
        self._yeah_snds = []

        self.name = name
        self.sex = sex
        if sex == "male":
            self.heshe = base.labels.PRONOUNS[0]  # noqa: F821
            self.hisher = base.labels.PRONOUNS[1]  # noqa: F821
            self.himher = base.labels.PRONOUNS[2]  # noqa: F821
        else:
            self.heshe = base.labels.PRONOUNS[3]  # noqa: F821
            self.hisher = base.labels.PRONOUNS[4]  # noqa: F821
            self.himher = base.labels.PRONOUNS[5]  # noqa: F821

        if desc:
            self._energy = desc["energy"]
            self.is_diseased = desc["is_diseased"]
            self.get_well_score = desc["get_well_score"]
            self.traits = desc["traits"]
            self.disabled_traits = desc["disabled_traits"]

            if self.is_diseased:
                taskMgr.doMethodLater(  # noqa: F821
                    60, self.get_well, self.id + "_get_well"
                )
        else:
            self._energy = 100
            self.is_diseased = False
            self.get_well_score = 0

            self.disabled_traits = []
            self.traits = []
            traits = copy.copy(base.labels.TRAITS)  # noqa: F821
            for _ in range(random.randint(0, 2)):
                self.traits.append(random.choice(take_random(traits)))
コード例 #11
0
ファイル: part.py プロジェクト: IlyaFaer/ForwardOnlyGame
    def give_cell(self, character):
        """Choose a non taken cell.

        Args:
            character (units.crew.character.Character):
                Unit to set to this part.

        Returns:
            dict: Position and rotation to set character.
        """
        if not self._cells:
            return

        self.chars.append(character)
        return take_random(self._cells)
コード例 #12
0
    def start_outing(self, type_):
        """Choose and start outing scenario.

        Args:
            type_ (str): Outing type.
        """
        if not self._outings[type_]:
            if type_ == "Looting":
                self._outings[type_] = copy.deepcopy(LOOTING)
            elif type_ == "Enemy Camp":
                self._outings[type_] = copy.deepcopy(ENEMY_CAMP)
            else:
                self._outings[type_] = copy.deepcopy(MEET)

        self._gui.start(take_random(self._outings[type_]))
コード例 #13
0
ファイル: crew.py プロジェクト: IlyaFaer/ForwardOnlyGame
    def _calc_cohesion(self, task):
        """Calculate the current crew cohesion.

        Relations between all the characters are tracked.
        While characters are staying together, cohesion
        between them increases. Total cohesion is calculated
        as a sum of all relations relatively to the number
        of all relations in the crew. Different unit classes
        have different cohesion factors.
        """
        for char1 in self.chars.values():
            for char2 in self.chars.values():
                if char1.id == char2.id:
                    continue

                rel_id = tuple(sorted([char1.id, char2.id]))
                factor = 1.35 if char1.current_part == char2.current_part else 1

                if (
                    base.labels.TRAITS[4][0]  # noqa: F821
                    in char1.traits + char2.traits
                    and char1.class_ != char2.class_
                ):
                    # Liberal
                    factor *= 1.15

                if rel_id in self._relations:
                    plus = COHESION_FACTORS[(char1.class_, char2.class_)] * factor
                    self._relations[rel_id] = min(100, plus + self._relations[rel_id])

                    # propagate traits from one character to another
                    if self._relations[rel_id] > 80 and chance(50):
                        pair = [char1, char2]
                        from_char = take_random(pair)
                        if from_char.traits:
                            trait = random.choice(from_char.traits)
                            if trait not in pair[0].traits and len(pair[0].traits) < 3:
                                pair[0].traits.append(trait)
                else:
                    self._relations[rel_id] = (
                        COHESION_FACTORS[(char1.class_, char2.class_)] * factor
                    )

        self._calc_total_cohesion()
        task.delayTime = 160
        return task.again
コード例 #14
0
ファイル: __init__.py プロジェクト: IlyaFaer/ForwardOnlyGame
    def explode_rocket(self, side):
        """Explode a rocket on the given side of the locomotive.

        Args:
            side (str): Side on which a rocket is exploded.
        """
        if side == "right":
            x_coor = -0.11
        elif side == "top":
            x_coor = 0
        else:
            x_coor = 0.11

        rocket_explosion = take_random(self._rocket_explosions)
        rocket_explosion.setPos(x_coor, 0.11, 0.33 if side == "top" else 0.22)
        rocket_explosion.start(self.model, render)  # noqa: F821
        rocket_explosion.softStart()

        self._rocket_explosions_snd.play()
        base.camera_ctrl.push()  # noqa: F821

        taskMgr.doMethodLater(  # noqa: F821
            0.8,
            self._stop_rocket_explosion,
            "disable_rocket_smoke",
            extraArgs=[rocket_explosion],
        )

        if self._armor_plate is None:
            self.get_damage(80)
            return

        if side == "left" and not self._armor_plate.cur_position == "right":
            self.get_damage(80)
            return

        if side == "right" and not self._armor_plate.cur_position == "left":
            self.get_damage(80)
            return

        if side == "top" and not self._armor_plate.cur_position == "top":
            self.get_damage(80)
コード例 #15
0
 def __spawn_enemy(self):
     self.enemy = take_random(self.__enemies)
     print("You found an enemy! A battle is about to start!")
     self.battle = True
コード例 #16
0
 def __collect_treasure(self):
     treasure = take_random(self.__treasures)
     print("You found a treasure!", str(treasure))
     self.hero.take_treasure(treasure)