From 15e4ba4a14d912f70b0862bd1f0af9339dcbc6c0 Mon Sep 17 00:00:00 2001 From: wushin Date: Wed, 1 Apr 2015 01:27:04 -0500 Subject: Remove killer/killable Death Clears default pvp Add Player Togglable PvP Flag Add Timer to PvP Flag (Anti-Spam) Add getpvpflag builtin --- src/map/atcommand.cpp | 93 ++++++-------------------------------------------- src/map/magic-stmt.cpp | 4 +-- src/map/map.hpp | 3 +- src/map/pc.cpp | 43 ++++++++++++++++++----- src/map/pc.hpp | 2 ++ src/map/script-fun.cpp | 32 +++++++++++++++++ 6 files changed, 82 insertions(+), 95 deletions(-) (limited to 'src/map') diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index cd51b70..2a5791e 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -4030,81 +4030,19 @@ ATCE atcommand_character_storage_list(Session *s, dumb_ptr sd, } static -ATCE atcommand_killer(Session *s, dumb_ptr sd, +ATCE atcommand_pvp(Session *s, dumb_ptr sd, ZString) { - sd->special_state.killer = !sd->special_state.killer; - - if (sd->special_state.killer) - clif_displaymessage(s, "You be a killa..."_s); - else - clif_displaymessage(s, "You gonna be own3d..."_s); - - return ATCE::OKAY; -} - -static -ATCE atcommand_charkiller(Session *s, dumb_ptr, - ZString message) -{ - CharName character; - - if (!asplit(message, &character)) - return ATCE::USAGE; - - dumb_ptr pl_sd = map_nick2sd(character); - if (pl_sd == nullptr) - return ATCE::EXIST; - - pl_sd->special_state.killer = !pl_sd->special_state.killer; - - if (pl_sd->special_state.killer) - { - clif_displaymessage(s, "The player is now a killer"_s); - clif_displaymessage(pl_sd->sess, "You are now a killer"_s); - } - else - { - clif_displaymessage(s, "The player is no longer a killer"_s); - clif_displaymessage(pl_sd->sess, "You are no longer a killer"_s); - } - - return ATCE::OKAY; -} - -static -ATCE atcommand_killable(Session *s, dumb_ptr sd, - ZString) -{ - sd->special_state.killable = !sd->special_state.killable; - - if (sd->special_state.killable) - clif_displaymessage(s, "You gonna be own3d..."_s); - else - clif_displaymessage(s, "You be a killa..."_s); - - return ATCE::OKAY; -} - -static -ATCE atcommand_charkillable(Session *s, dumb_ptr, - ZString message) -{ - CharName character; - - if (!asplit(message, &character)) - return ATCE::USAGE; - - dumb_ptr pl_sd = map_nick2sd(character); - if (pl_sd == nullptr) - return ATCE::EXIST; + if (sd->pvp_timer) + return ATCE::OKAY; - pl_sd->special_state.killable = !pl_sd->special_state.killable; + sd->state.pvpon = !sd->state.pvpon; + pc_setpvptimer(sd, battle_config.player_pvp_time); - if (pl_sd->special_state.killable) - clif_displaymessage(s, "The player is now killable"_s); + if (sd->state.pvpon) + clif_displaymessage(s, "##3PvP : ##BOn"_s); else - clif_displaymessage(s, "The player is no longer killable"_s); + clif_displaymessage(s, "##3PvP : ##BOff"_s); return ATCE::OKAY; } @@ -5236,21 +5174,12 @@ Map atcommand_info = {"addwarp"_s, {" "_s, 80, atcommand_addwarp, "Create a new permanent warp"_s}}, - {"killer"_s, {""_s, - 60, atcommand_killer, - "Toggle whether you are a killer"_s}}, - {"charkiller"_s, {""_s, - 60, atcommand_charkiller, - "Toggle whether a player is a killer"_s}}, + {"pvp"_s, {""_s, + 0, atcommand_pvp, + "Toggle your pvp flag"_s}}, {"npcmove"_s, {" "_s, 80, atcommand_npcmove, "Force an NPC to move on the map"_s}}, - {"killable"_s, {""_s, - 60, atcommand_killable, - "Toggle whether you are killable"_s}}, - {"charkillable"_s, {""_s, - 60, atcommand_charkillable, - "Toggle whether a player is killable"_s}}, {"chareffect"_s, {" "_s, 40, atcommand_chareffect, "Apply effect type with arg 0 to a player"_s}}, diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp index c69dafa..544b290 100644 --- a/src/map/magic-stmt.cpp +++ b/src/map/magic-stmt.cpp @@ -773,8 +773,8 @@ int op_injure(dumb_ptr env, Slice args) if (target->bl_type == BL::PC && !target->bl_m->flag.get(MapFlag::PVP) - && !target->is_player()->special_state.killable - && (caster->bl_type != BL::PC || !caster->is_player()->special_state.killer)) + && (caster->bl_type != BL::PC) + && (!target->is_player()->state.pvpon && !caster->is_player()->state.pvpon)) return 0; /* Cannot damage other players outside of pvp */ if (target != caster) diff --git a/src/map/map.hpp b/src/map/map.hpp index 3dd03e7..9e15851 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -142,11 +142,10 @@ struct map_session_data : block_list, SessionData unsigned shroud_disappears_on_pickup:1; unsigned shroud_disappears_on_talk:1; unsigned seen_motd:1; + unsigned pvpon:1; } state; struct { - unsigned killer:1; - unsigned killable:1; unsigned unbreakable_weapon:1; unsigned unbreakable_armor:1; unsigned deaf:1; diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 7d04785..6a94f31 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -288,16 +288,10 @@ int pc_iskiller(dumb_ptr src, { nullpo_retz(src); - if (src->bl_type != BL::PC) + if (src->bl_type != BL::PC || target->bl_type != BL::PC) return 0; - if (src->special_state.killer) + if (src->state.pvpon && target->state.pvpon && !src->bl_m->flag.get(MapFlag::NOPVP)) return 1; - - if (target->bl_type != BL::PC) - return 0; - if (target->special_state.killable) - return 1; - return 0; } @@ -319,6 +313,33 @@ int distance(int x0, int y0, int x1, int y1) return dx > dy ? dx : dy; } +static +void pc_pvp_timer(TimerData *, tick_t, BlockId id) +{ + dumb_ptr sd = map_id2sd(id); + + assert (sd != nullptr); + assert (sd->bl_type == BL::PC); +} + +int pc_setpvptimer(dumb_ptr sd, interval_t val) +{ + nullpo_retz(sd); + + sd->pvp_timer = Timer(gettick() + val, + std::bind(pc_pvp_timer, ph::_1, ph::_2, + sd->bl_id)); + return 0; +} + +int pc_delpvptimer(dumb_ptr sd) +{ + nullpo_retz(sd); + + sd->pvp_timer.cancel(); + return 0; +} + static void pc_invincible_timer(TimerData *, tick_t, BlockId id) { @@ -378,7 +399,6 @@ int pc_setrestartvalue(dumb_ptr sd, int type) clif_updatestatus(sd, SP::SP); sd->heal_xp = 0; // [Fate] Set gainable xp for healing this player to 0 - return 0; } @@ -899,6 +919,7 @@ int pc_calcstatus(dumb_ptr sd, int first) int bl; int aspd_rate, refinedef = 0; int str, dstr, dex; + int b_pvpon = 0; nullpo_retz(sd); @@ -927,6 +948,8 @@ int pc_calcstatus(dumb_ptr sd, int first) b_mdef = sd->mdef; b_mdef2 = sd->mdef2; b_base_atk = sd->base_atk; + if (!pc_isdead(sd) && sd->state.pvpchannel == 1) + b_pvpchannel = sd->state.pvpchannel; sd->max_weight = max_weight_base_0 + sd->status.attrs[ATTR::STR] * 300; @@ -1399,6 +1422,8 @@ int pc_calcstatus(dumb_ptr sd, int first) clif_updatestatus(sd, SP::HP); if (b_sp != sd->status.sp) clif_updatestatus(sd, SP::SP); + if (b_pvpon != sd->state.pvpon) + sd->state.pvpon = b_pvpon; return 0; } diff --git a/src/map/pc.hpp b/src/map/pc.hpp index ba0a46f..56f0491 100644 --- a/src/map/pc.hpp +++ b/src/map/pc.hpp @@ -170,6 +170,8 @@ void pc_setstand(dumb_ptr sd); void pc_cleanup(dumb_ptr sd); // [Fate] Clean up after a logged-out PC int pc_read_gm_account(Session *, const std::vector>&); +int pc_setpvptimer(dumb_ptr sd, interval_t); +int pc_delpvptimer(dumb_ptr sd); int pc_setinvincibletimer(dumb_ptr sd, interval_t); int pc_delinvincibletimer(dumb_ptr sd); int pc_logout(dumb_ptr sd); // [fate] Player logs out diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 8c25266..bde1458 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -2175,6 +2175,36 @@ void builtin_pvpoff(ScriptState *st) } } +static +void builtin_pvp(ScriptState *st) +{ + dumb_ptr sd = script_rid2sd(st); + int flag; + flag = conv_num(st, &AARG(0)); + if (flag > 1) + flag = 1; + + sd->state.pvpon = flag; +} + +static +void builtin_getpvpflag(ScriptState *st) +{ + dumb_ptr sd = script_rid2sd(st); + int num = conv_num(st, &AARG(0)); + + switch (num){ + case 0: + num = sd->state.pvpon; + break; + case 1: + flag = bool(sd->status.option & Opt0::HIDE); + break; + } + + push_int(st->stack, num); +} + /*========================================== * NPCエモーション *------------------------------------------ @@ -3078,6 +3108,8 @@ BuiltinFunction builtin_functions[] = BUILTIN(getmapflag, "Mi"_s, 'i'), BUILTIN(pvpon, "M"_s, '\0'), BUILTIN(pvpoff, "M"_s, '\0'), + BUILTIN(pvp, "i"_s, '\0'), + BUILTIN(getpvpflag, "i"_s, 'i'), BUILTIN(emotion, "i"_s, '\0'), BUILTIN(mapwarp, "MMxy"_s, '\0'), BUILTIN(cmdothernpc, "ss"_s, '\0'), -- cgit v1.2.3-60-g2f50 From 7f31bde507bee63e36ddaefd5d16ab314b98b601 Mon Sep 17 00:00:00 2001 From: mekolat Date: Fri, 3 Apr 2015 11:03:26 -0400 Subject: add getpvpflag builtin --- src/map/script-fun.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/map') diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index bde1458..f08cf60 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -2192,17 +2192,18 @@ void builtin_getpvpflag(ScriptState *st) { dumb_ptr sd = script_rid2sd(st); int num = conv_num(st, &AARG(0)); + int flag = 0; switch (num){ case 0: - num = sd->state.pvpon; + flag = sd->state.pvpon; break; case 1: flag = bool(sd->status.option & Opt0::HIDE); break; } - push_int(st->stack, num); + push_int(st->stack, flag); } /*========================================== -- cgit v1.2.3-60-g2f50 From ee8dff7687f120cbe55dccc56c1ae1f711bb68b5 Mon Sep 17 00:00:00 2001 From: mekolat Date: Fri, 3 Apr 2015 14:20:01 -0400 Subject: make pvp use channels --- src/map/atcommand.cpp | 14 ++++++++------ src/map/magic-stmt.cpp | 2 +- src/map/map.hpp | 2 +- src/map/pc.cpp | 10 ++++++---- src/map/script-fun.cpp | 12 ++++++------ 5 files changed, 22 insertions(+), 18 deletions(-) (limited to 'src/map') diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 2a5791e..7c165ef 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -4033,17 +4033,19 @@ static ATCE atcommand_pvp(Session *s, dumb_ptr sd, ZString) { - if (sd->pvp_timer) + int chan = sd->state.pvpchannel; + if (sd->pvp_timer || (chan > 1)) return ATCE::OKAY; - sd->state.pvpon = !sd->state.pvpon; - pc_setpvptimer(sd, battle_config.player_pvp_time); - - if (sd->state.pvpon) + if (chan < 1) { + sd->state.pvpchannel = 1; clif_displaymessage(s, "##3PvP : ##BOn"_s); - else + } else { + sd->state.pvpchannel = 0; clif_displaymessage(s, "##3PvP : ##BOff"_s); + } + pc_setpvptimer(sd, battle_config.player_pvp_time); return ATCE::OKAY; } diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp index 544b290..fdeac3a 100644 --- a/src/map/magic-stmt.cpp +++ b/src/map/magic-stmt.cpp @@ -774,7 +774,7 @@ int op_injure(dumb_ptr env, Slice args) if (target->bl_type == BL::PC && !target->bl_m->flag.get(MapFlag::PVP) && (caster->bl_type != BL::PC) - && (!target->is_player()->state.pvpon && !caster->is_player()->state.pvpon)) + && ((caster->is_player()->state.pvpchannel > 1) && (target->is_player()->state.pvpchannel != caster->is_player()->state.pvpchannel))) return 0; /* Cannot damage other players outside of pvp */ if (target != caster) diff --git a/src/map/map.hpp b/src/map/map.hpp index 9e15851..f57dcee 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -142,7 +142,7 @@ struct map_session_data : block_list, SessionData unsigned shroud_disappears_on_pickup:1; unsigned shroud_disappears_on_talk:1; unsigned seen_motd:1; - unsigned pvpon:1; + unsigned pvpchannel; } state; struct { diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 6a94f31..8b0391b 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -290,7 +290,9 @@ int pc_iskiller(dumb_ptr src, if (src->bl_type != BL::PC || target->bl_type != BL::PC) return 0; - if (src->state.pvpon && target->state.pvpon && !src->bl_m->flag.get(MapFlag::NOPVP)) + if ((src->state.pvpchannel == 1) && (target->state.pvpchannel == 1) && !src->bl_m->flag.get(MapFlag::NOPVP)) + return 1; + if ((src->state.pvpchannel > 1) && (target->state.pvpchannel == src->state.pvpchannel)) // this one does not respect NOPVP return 1; return 0; } @@ -919,7 +921,7 @@ int pc_calcstatus(dumb_ptr sd, int first) int bl; int aspd_rate, refinedef = 0; int str, dstr, dex; - int b_pvpon = 0; + int b_pvpchannel = 0; nullpo_retz(sd); @@ -1422,8 +1424,8 @@ int pc_calcstatus(dumb_ptr sd, int first) clif_updatestatus(sd, SP::HP); if (b_sp != sd->status.sp) clif_updatestatus(sd, SP::SP); - if (b_pvpon != sd->state.pvpon) - sd->state.pvpon = b_pvpon; + if (b_pvpchannel != sd->state.pvpchannel) + sd->state.pvpchannel = b_pvpchannel; return 0; } diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index f08cf60..1d587fd 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -2176,15 +2176,15 @@ void builtin_pvpoff(ScriptState *st) } static -void builtin_pvp(ScriptState *st) +void builtin_setpvpchannel(ScriptState *st) { dumb_ptr sd = script_rid2sd(st); int flag; flag = conv_num(st, &AARG(0)); - if (flag > 1) - flag = 1; + if (flag < 1) + flag = 0; - sd->state.pvpon = flag; + sd->state.pvpchannel = flag; } static @@ -2196,7 +2196,7 @@ void builtin_getpvpflag(ScriptState *st) switch (num){ case 0: - flag = sd->state.pvpon; + flag = sd->state.pvpchannel; break; case 1: flag = bool(sd->status.option & Opt0::HIDE); @@ -3109,7 +3109,7 @@ BuiltinFunction builtin_functions[] = BUILTIN(getmapflag, "Mi"_s, 'i'), BUILTIN(pvpon, "M"_s, '\0'), BUILTIN(pvpoff, "M"_s, '\0'), - BUILTIN(pvp, "i"_s, '\0'), + BUILTIN(setpvpchannel, "i"_s, '\0'), BUILTIN(getpvpflag, "i"_s, 'i'), BUILTIN(emotion, "i"_s, '\0'), BUILTIN(mapwarp, "MMxy"_s, '\0'), -- cgit v1.2.3-60-g2f50 From 8e8876474eddefe474528c73851b3af2c6d9327f Mon Sep 17 00:00:00 2001 From: mekolat Date: Fri, 3 Apr 2015 14:27:37 -0400 Subject: add charpvp atcommand --- src/map/atcommand.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/map') diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 7c165ef..f226706 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -4049,6 +4049,25 @@ ATCE atcommand_pvp(Session *s, dumb_ptr sd, return ATCE::OKAY; } +static +ATCE atcommand_charpvp(Session *, dumb_ptr, + ZString message) +{ + CharName character; + int channel; + + if (!extract(message, record<' '>(&character, &channel))) + return ATCE::USAGE; + + dumb_ptr pl_sd = map_nick2sd(character); + if (pl_sd == nullptr) + return ATCE::EXIST; + + pl_sd->state.pvpchannel = channel; + + return ATCE::OKAY; +} + static ATCE atcommand_npcmove(Session *, dumb_ptr, ZString message) @@ -5182,6 +5201,9 @@ Map atcommand_info = {"npcmove"_s, {" "_s, 80, atcommand_npcmove, "Force an NPC to move on the map"_s}}, + {"charpvp"_s, {" "_s, + 40, atcommand_charpvp, + "Set the pvp channel of another player"_s}}, {"chareffect"_s, {" "_s, 40, atcommand_chareffect, "Apply effect type with arg 0 to a player"_s}}, -- cgit v1.2.3-60-g2f50