コード例 #1
0
ファイル: units.py プロジェクト: dan-hill/jabberfire
    def post(self):
        json = request.json['unit']
        print json
        unit = UnitModel(
            status=json['status'],
            tag=json['tag'],
            purchase_cost=json['purchase_cost'],
            warranty_expiration=dateutil.parser.parse(json['warranty_expiration']),
            end_of_life=dateutil.parser.parse(json['end_of_life']))

        unit.asset = Asset.find(id=json['asset'])
        unit.save()

        model = {
            'unit': {
                'id': unit.id,
                'status': unit.status,
                'tag': unit.tag,
                'purchase_cost': unit.purchase_cost,
                'warranty_expiration': unit.warranty_expiration,
                'end_of_life': unit.end_of_life,
                'asset': unit.asset_id,
                'asset_id': unit.asset_id
            }
        }

        print model
        return jsonify(model), 201
コード例 #2
0
ファイル: units.py プロジェクト: dan-hill/jabberfire
    def get(self):
        units = []
        for unit in UnitModel.list():
            units.append({
                'id': unit.id,
                'status': unit.status,
                'tag': unit.tag,
                'note': unit.note,
                'purchase_cost': unit.purchase_cost,
                'warranty_expiration': unit.warranty_expiration,
                'end_of_life': unit.end_of_life,
                'asset': unit.asset_id,
            })

        return jsonify({'units': units})
コード例 #3
0
def load_Unit():
    """Load units from units into database."""

    print "units"

    Unit.query.delete()

    for row in open("seed_data/units"):
        row = row.strip()
        items = row.split(",")

        unit = Unit(unit_name=items[0])

        db.session.add(unit)

        db.session.commit()
コード例 #4
0
ファイル: unit.py プロジェクト: dan-hill/jabberfire
    def get(self, id):
        unit = UnitModel.find(id=id)

        model = {
            'unit': {
                'id': unit.id,
                'status': unit.status,
                'tag': unit.tag,
                'note': unit.note,
                'image': unit.image,
                'asset': unit.asset_id,
                'purhase_cost': unit.purchase_cost,
                'warranty_expiration': unit.warranty_expiration,
                'end_of_life': unit.end_of_life,
            }
        }
        return jsonify(model)
コード例 #5
0
    def get(self, id):
        unit = UnitModel.find(id=id)

        model = {
            'unit': {
                'id': unit.id,
                'status': unit.status,
                'tag': unit.tag,
                'note': unit.note,
                'image': unit.image,
                'asset': unit.asset_id,
                'purhase_cost': unit.purchase_cost,
                'warranty_expiration': unit.warranty_expiration,
                'end_of_life': unit.end_of_life,
            }
        }
        return jsonify(model)
コード例 #6
0
    def _handle_turn_units(self, msg, is_dead_unit=False):
        if not is_dead_unit:
            self._map._clear_units()
            for player in self._players:
                player.units.clear()
                player.played_units.clear()
                player.hasted_units.clear()
                player.duplicate_units.clear()
                player.range_upgraded_unit = None
                player.damage_upgraded_unit = None
        else:
            for player in self._players:
                player.died_units.clear()

        unit_input_list = []

        for unit_msg in msg:
            unit_id = unit_msg["unitId"]
            player = self.get_player_by_id(player_id=unit_msg["playerId"])
            base_unit = self._base_units[unit_msg["typeId"]]

            if not unit_msg['target'] == -1:
                target_cell = Cell(row=unit_msg["targetCell"]["row"],
                                   col=unit_msg["targetCell"]["col"])
            else:
                target_cell = None
            unit = Unit(
                unit_id=unit_id,
                base_unit=base_unit,
                cell=self._map.get_cell(unit_msg["cell"]["row"],
                                        unit_msg["cell"]["col"]),
                path=self._map.get_path_by_id(unit_msg["pathId"]),
                hp=unit_msg["hp"],
                damage_level=unit_msg["damageLevel"],
                range_level=unit_msg["rangeLevel"],
                is_duplicate=unit_msg["isDuplicate"],
                is_hasted=unit_msg["isHasted"],
                range=unit_msg["range"],
                attack=unit_msg["attack"],
                target=None,  # will be set later when all units are in set
                target_cell=target_cell,
                affected_spells=[
                    self.get_cast_spell_by_id(cast_spell_id)
                    for cast_spell_id in unit_msg["affectedSpells"]
                ],
                target_if_king=None
                if self.get_player_by_id(unit_msg["target"]) is None else
                self.get_player_by_id(unit_msg["target"]).king,
                player_id=unit_msg["playerId"])
            unit_input_list.append(unit)

            if unit.path is not None:
                if self.get_player_by_id(
                        unit.player_id
                ).king.center in unit.path.cells and unit.path.cells[
                        0] != self.get_player_by_id(
                            unit.player_id).king.center:
                    unit.path = Path(path=unit.path)
                    unit.path.cells.reverse()
                if self._get_friend_by_id(
                        unit.player_id
                ).king.center in unit.path.cells and unit.path.cells[
                        0] != self._get_friend_by_id(
                            unit.player_id).king.center:
                    unit.path = Path(path=unit.path)
                    unit.path.cells.reverse()

            if not is_dead_unit:
                self._map._add_unit_in_cell(unit.cell.row, unit.cell.col, unit)
                player.units.append(unit)
                if unit_msg["wasDamageUpgraded"]:
                    player.damage_upgraded_unit = unit
                if unit_msg["wasRangeUpgraded"]:
                    player.range_upgraded_unit = unit
                if unit_msg["wasPlayedThisTurn"]:
                    player.played_units.append(unit)
                if unit.is_hasted:
                    player.hasted_units.append(unit)
                if unit.is_duplicate:
                    player.duplicate_units.append(unit)
            else:
                player.died_units.append(unit)

        for i in range(len(unit_input_list)):
            unit = unit_input_list[i]
            if unit.target_if_king is not None:
                unit.target = None
            else:
                unit.target = self.get_unit_by_id(msg[i]["target"])
コード例 #7
0
    def _handle_turn_units(self, msg, is_dead_unit=False):
        if not is_dead_unit:
            self._map.clear_units()
            for player in self._players:
                player.units.clear()
                player.played_units.clear()
                player.hasted_units.clear()
                player.duplicate_units.clear()
                player.range_upgraded_unit = None
                player.damage_upgraded_unit = None
        else:
            for player in self._players:
                player.died_units.clear()

        for unit_msg in msg:
            unit_id = unit_msg["unitId"]
            player = self.get_player_by_id(player_id=unit_msg["playerId"])
            base_unit = self._base_units[unit_msg["typeId"]]

            if not unit_msg['target'] == -1:
                target_cell = Cell(row=unit_msg["targetCell"]["row"],
                                   col=unit_msg["targetCell"]["col"])
            else:
                target_cell = None
            unit = Unit(unit_id=unit_id,
                        base_unit=base_unit,
                        cell=self._map.get_cell(unit_msg["cell"]["row"],
                                                unit_msg["cell"]["col"]),
                        path=self._map.get_path_by_id(unit_msg["pathId"]),
                        hp=unit_msg["hp"],
                        damage_level=unit_msg["damageLevel"],
                        range_level=unit_msg["rangeLevel"],
                        is_duplicate=unit_msg["isDuplicate"],
                        is_hasted=unit_msg["isHasted"],
                        range=unit_msg["range"],
                        attack=unit_msg["attack"],
                        target=unit_msg["target"],
                        target_cell=target_cell,
                        affected_spells=[
                            self.get_cast_spell_by_id(cast_spell_id)
                            for cast_spell_id in unit_msg["affectedSpells"]
                        ],
                        target_if_king=None
                        if self.get_player_by_id(unit_msg["target"]) is None
                        else self.get_player_by_id(unit_msg["target"]).king,
                        player_id=unit_msg["playerId"])
            if not is_dead_unit:
                self._map.add_unit_in_cell(unit.cell.row, unit.cell.col, unit)
                player.units.append(unit)
                if unit_msg["wasDamageUpgraded"]:
                    player.damage_upgraded_unit = unit
                if unit_msg["wasRangeUpgraded"]:
                    player.range_upgraded_unit = unit
                if unit_msg["wasPlayedThisTurn"]:
                    player.played_units.append(unit)
                if unit.is_hasted:
                    player.hasted_units.append(unit)
                if unit.is_duplicate:
                    player.duplicate_units.append(unit)
            else:
                player.died_units.append(unit)
        for unit in self._map.units:
            if unit.target == -1 or unit.target_if_king is not None:
                unit.target = None
            else:
                unit.target = self.get_unit_by_id(unit.target)