示例#1
0
void Tournament::player_damage(identifier_t owner, Player *p, NPC *npc, int damage,
    const std::string& weapon)
{
    if (damage) {
        check_friendly_fire(owner, p);

        /* get damage levels */
        int damage2 = damage / (p->state.server_state.armor ? 2 : 1);

        /* reduce armor */
        if (damage >= p->state.server_state.armor) {
            p->state.server_state.armor = 0;
        } else {
            p->state.server_state.armor -= damage;
        }

        /* reduce health */
        if (damage2 >= p->state.server_state.health) {
            /* player dies */
            player_dies(p, "");

            /* increment owner's frag counter */
            std::string verb("killed");
            if (npc) {
                const std::string& die_verb = npc->get_value("die_verb");
                if (die_verb.length()) {
                    verb = die_verb;
                }
            }
            for (Players::iterator it = players.begin(); it != players.end(); it++) {
                Player *fp = *it;
                if (fp->state.id == owner) {
                    if (fp != p) {
                        fp->state.server_state.frags++;
                        frag_point(fp, p);
                        std::string msg(fp->get_player_name() + " " + verb + " " + p->get_player_name());
                        add_msg_response(msg.c_str());
                        if (logger) {
                            logger->log(ServerLogger::LogTypeFrag, msg, fp, p,
                                (npc ? npc->get_name().c_str() : weapon.c_str()));
                        }
                    } else {
                        fp->state.server_state.score -= 1;
                        std::string msg(fp->get_player_name() + " " + verb + " himself");
                        add_msg_response(msg.c_str());
                        if (logger) {
                            logger->log(ServerLogger::LogTypeKill, msg, fp, p,
                                (npc ? npc->get_name().c_str() : weapon.c_str()));
                        }
                    }
                    break;
                }
            }
        } else {
            add_state_response(GPCPlayerHurt, 0, 0);
            p->state.server_state.health -= damage2;
        }
    }
}
示例#2
0
void Tournament::player_dies(Player *p, const std::string& die_message) {
    player_died(p);
    p->state.server_state.health = 0;
    p->state.server_state.flags |= PlayerServerFlagDead;
    p->state.server_state.kills++;
    if (die_message.length()) {
        add_msg_response(die_message.c_str());
    }

    try {
        Animation *tempani = resources.get_animation(properties.get_value("die_animation"));

        GAnimation *ani = new GAnimation;
        memset(ani, 0, sizeof(GAnimation));
        strncpy(ani->animation_name, tempani->get_name().c_str(), NameLength - 1);
        strncpy(ani->sound_name, properties.get_value("die_sound").c_str(), NameLength - 1);

        TileGraphic *tg = p->get_characterset()->get_tile(DirectionLeft, CharacterAnimationStanding)->get_tilegraphic();
        TileGraphic *tga = tempani->get_tile()->get_tilegraphic();

        int x = static_cast<int>(p->state.client_server_state.x) + tg->get_width() / 2 - tga->get_width() / 2;
        int y = static_cast<int>(p->state.client_server_state.y) - tg->get_height() / 2 - tga->get_height() / 2;

        ani->id = ++animation_id;
        ani->x = x;
        ani->y = y;
        ani->to_net();
        add_state_response(GPCAddAnimation, sizeof(GAnimation), ani);
    } catch (const Exception& e) {
        subsystem << e.what() << std::endl;
    }
}
示例#3
0
void TournamentSR::round_finished_set_time(Player *p, GTransportTime *race) {
    /* server side */
    TimesOfPlayer *top = get_times_of_player(p);
    if (top) {
        GTransportTime *tm = new GTransportTime;
        *tm = *race;
        tm->to_net();
        add_state_response(GPCScoreTransportRaw, GTransportTimeLen, tm);
        float diff = race->ms / 1000.0f;

        TimesOfPlayer& first_top = times_of_players[0];
        bool has_entries = first_top.times.size() > 0;
        float best_time = first_top.best;

        update_stats(top, diff);

        if ((has_entries && diff < best_time) || !has_entries) {
            sprintf(buffer, "new record of %s: %.2f", p->get_player_name().c_str(), diff);
            add_msg_response(buffer);
            add_sound_response("round_complete_best");
            if (logger) {
                logger->log(ServerLogger::LogTypeRoundFinished, buffer, p, 0, &diff);
            }
        } else {
            add_sound_response("round_complete");
            if (logger) {
                logger->log(ServerLogger::LogTypeRoundFinished, "round completed", p, 0, &diff);
            }
        }
    }
}
示例#4
0
bool Tournament::player_joins(Player *p, playerflags_t flags) {
    std::string msg(p->get_player_name() + " joins the game");
    add_msg_response(msg.c_str());
    if (logger) {
        logger->log(ServerLogger::LogTypeJoin, msg, p);
    }

    return true;
}
bool TournamentTeam::player_joins(Player *p, playerflags_t flags) {
    std::string msg(p->get_player_name() + " joins the ");
    if (flags & PlayerServerFlagTeamRed) {
        msg += team_red_name;
        p->state.server_state.flags |= PlayerServerFlagTeamRed;
        if (logger) {
            logger->log(ServerLogger::LogTypeRedTeamJoin, msg, p);
        }
    } else {
        msg += team_blue_name;
        if (logger) {
            logger->log(ServerLogger::LogTypeBlueTeamJoin, msg, p);
        }
    }
    add_msg_response(msg.c_str());

    return true;
}