Skip to content
This repository was archived by the owner on Dec 4, 2020. It is now read-only.

Commit 9fd279e

Browse files
authored
Merge pull request #1103 from zach2good/enable_pvp
Enable basic PVP
2 parents 40c2491 + 88136e0 commit 9fd279e

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

scripts/commands/setallegiance.lua

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---------------------------------------------------------------------------------------------------
2+
-- func: setallegiance
3+
-- desc: Sets the players allegiance.
4+
---------------------------------------------------------------------------------------------------
5+
cmdprops =
6+
{
7+
permission = 1,
8+
parameters = "is"
9+
}
10+
11+
function error(player, msg)
12+
player:PrintToPlayer(msg)
13+
player:PrintToPlayer("!setallegiance <allegiance> <player>")
14+
end
15+
16+
function onTrigger(player, allegiance, target)
17+
-- validate target
18+
local targ
19+
local cursor_target = player:getCursorTarget()
20+
21+
if target then
22+
targ = GetPlayerByName(target)
23+
if not targ then
24+
error(player, string.format("Player named '%s' not found!", target))
25+
return
26+
end
27+
elseif cursor_target and not cursor_target:isNPC() then
28+
targ = cursor_target
29+
else
30+
targ = player
31+
end
32+
33+
if allegiance == nil or (allegiance < 0 or allegiance > 6) then
34+
error(player, "Improper allegiance passed. Valid Values: 0 to 6")
35+
return
36+
end
37+
38+
local toString = {"Mob", "Player", "San d'Oria", "Bastok", "Windurst", "Wyverns", "Griffons"}
39+
40+
player:PrintToPlayer(string.format("You set %s's allegiance to %s", targ:getName(), toString[allegiance + 1]))
41+
targ:setAllegiance(allegiance)
42+
end

src/map/entities/baseentity.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ enum ALLEGIANCETYPE
135135
ALLEGIANCE_PLAYER = 1,
136136
ALLEGIANCE_SAN_DORIA = 2,
137137
ALLEGIANCE_BASTOK = 3,
138-
ALLEGIANCE_WINDURST = 4
138+
ALLEGIANCE_WINDURST = 4,
139+
ALLEGIANCE_WYVERNS = 5,
140+
ALLEGIANCE_GRIFFONS = 6,
139141
};
140142

141143
enum UPDATETYPE

src/map/entities/battleentity.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,17 +1186,37 @@ bool CBattleEntity::ValidTarget(CBattleEntity* PInitiator, uint16 targetFlags)
11861186
{
11871187
if (!isDead())
11881188
{
1189-
if (allegiance == (PInitiator->allegiance % 2 == 0 ? PInitiator->allegiance + 1 : PInitiator->allegiance - 1))
1189+
// Teams PVP
1190+
if (allegiance >= ALLEGIANCE_WYVERNS &&
1191+
PInitiator->allegiance >= ALLEGIANCE_WYVERNS)
11901192
{
1191-
return true;
1193+
return allegiance != PInitiator->allegiance;
11921194
}
1195+
1196+
// Nation PVP
1197+
if ((allegiance >= ALLEGIANCE_SAN_DORIA && allegiance <= ALLEGIANCE_WINDURST) &&
1198+
(PInitiator->allegiance >= ALLEGIANCE_SAN_DORIA && PInitiator->allegiance <= ALLEGIANCE_WINDURST))
1199+
{
1200+
return allegiance != PInitiator->allegiance;
1201+
}
1202+
1203+
// PVE
1204+
if (allegiance <= ALLEGIANCE_PLAYER &&
1205+
PInitiator->allegiance <= ALLEGIANCE_PLAYER)
1206+
{
1207+
return allegiance != PInitiator->allegiance;
1208+
}
1209+
1210+
return false;
11931211
}
11941212
}
1213+
11951214
if ((targetFlags & TARGET_SELF) && (this == PInitiator || (PInitiator->objtype == TYPE_PET &&
11961215
static_cast<CPetEntity*>(PInitiator)->getPetType() == PETTYPE_AUTOMATON && this == PInitiator->PMaster)))
11971216
{
11981217
return true;
11991218
}
1219+
12001220
return false;
12011221
}
12021222

src/map/entities/charentity.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,9 @@ void CCharEntity::Die(duration _duration)
16871687
PAI->ClearStateStack();
16881688
PAI->Internal_Die(_duration);
16891689

1690+
// If player allegiance is not reset on death they will auto-homepoint
1691+
allegiance = ALLEGIANCE_PLAYER;
1692+
16901693
// reraise modifiers
16911694
if (this->getMod(Mod::RERAISE_I) > 0)
16921695
m_hasRaise = 1;

src/map/lua/lua_baseentity.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4974,6 +4974,8 @@ inline int32 CLuaBaseEntity::setAllegiance(lua_State* L)
49744974
ALLEGIANCETYPE allegiance = (ALLEGIANCETYPE)lua_tointeger(L, 1);
49754975

49764976
m_PBaseEntity->allegiance = allegiance;
4977+
m_PBaseEntity->updatemask |= UPDATE_HP;
4978+
49774979
return 0;
49784980
}
49794981

0 commit comments

Comments
 (0)