Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New methods to handle summon creatures #4814

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions data/creaturescripts/scripts/drop_loot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,7 @@ function onDeath(player, corpse, killer, mostDamageKiller, lastHitUnjustified, m
local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
local isRedOrBlack = table.contains({SKULL_RED, SKULL_BLACK}, player:getSkull())
if amulet and amulet.itemid == ITEM_AMULETOFLOSS and not isRedOrBlack then
local isPlayer = false
if killer then
if killer:isPlayer() then
isPlayer = true
else
local master = killer:getMaster()
if master and master:isPlayer() then
isPlayer = true
end
end
end

if not isPlayer or not player:hasBlessing(6) then
if not killer or not killer:hasPlayerOwned() or not player:hasBlessing(6) then
player:removeItem(ITEM_AMULETOFLOSS, 1, -1, false)
end
else
Expand Down
11 changes: 3 additions & 8 deletions data/creaturescripts/scripts/player_death.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ local function getKiller(killer)
return false, "field item"
end

if killer:isPlayer() then
return true, killer:getName()
local player = killer:getPlayerOwned()
if player and player ~= killer then
return true, player:getName()
end

local master = killer:getMaster()
if master and master ~= killer and master:isPlayer() then
return true, master:getName()
end

return false, killer:getName()
end

Expand Down
4 changes: 2 additions & 2 deletions data/lib/compat/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ function doSetMonsterTarget(cid, target)
return false
end

if monster:getMaster() then
if monster:isSummon() then
return true
end

Expand All @@ -913,7 +913,7 @@ function doMonsterChangeTarget(cid)
return false
end

if monster:getMaster() then
if monster:isSummon() then
return true
end

Expand Down
2 changes: 1 addition & 1 deletion data/scripts/actions/others/music_box.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ local config = {
local musicBox = Action()

function musicBox.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not target:isCreature() or not target:isMonster() or target:getMaster() then
if not target:isCreature() or not target:isMonster() or target:isSummon() then
return false
end

Expand Down
2 changes: 1 addition & 1 deletion data/scripts/actions/others/nail_case.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local messages = {
local nailCase = Action()

function nailCase.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not target:isCreature() or not target:isMonster() or target:getMaster() then
if not target:isCreature() or not target:isMonster() or target:isSummon() then
return false
end

Expand Down
2 changes: 1 addition & 1 deletion data/scripts/actions/others/taming.lua
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ function taming.onUse(player, item, fromPosition, target, toPosition, isHotkey)
end

if target.type == TYPE_MONSTER then
if target:getMaster() then
if target:isSummon() then
return false
end
end
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/creaturescripts/monster/white_deer_death.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local creatureevent = CreatureEvent("WhiteDeerDeath")

function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
local targetMonster = creature:getMonster()
if not targetMonster or targetMonster:getMaster() then
if not targetMonster or targetMonster:isSummon() then
return true
end

Expand Down
2 changes: 1 addition & 1 deletion data/scripts/creaturescripts/monster/white_deer_scouts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local creatureevent = CreatureEvent("WhiteDeerScouts")

function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
local targetMonster = creature:getMonster()
if not targetMonster or targetMonster:getMaster() then
if not targetMonster or targetMonster:isSummon() then
return true
end

Expand Down
2 changes: 1 addition & 1 deletion data/scripts/creaturescripts/player/bestiary_kills.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ local creatureEvent = CreatureEvent("BestiaryKills")

function creatureEvent.onKill(player, target)
local monster = target:getMonster()
if not monster or monster:getMaster() then
if not monster or monster:isSummon() then
return true
end

Expand Down
3 changes: 1 addition & 2 deletions data/scripts/spells/healing/mass_healing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ function spell.onCastSpell(creature, variant)
local min = (creature:getLevel() / 5) + (creature:getMagicLevel() * 4.6) + 100
local max = (creature:getLevel() / 5) + (creature:getMagicLevel() * 9.6) + 125
for _, target in ipairs(combat:getTargets(creature, variant)) do
local master = target:getMaster()
if target:isPlayer() or master and master:isPlayer() then
if target:hasPlayerOwned() then
doTargetCombat(creature, target, COMBAT_HEALING, min, max)
end
end
Expand Down
3 changes: 1 addition & 2 deletions data/scripts/spells/monster/frozen_minion_beam.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ combat:setArea(createCombatArea(AREA_BEAM7))
function onTargetCreature(creature, target)
local min = 200
local max = 700
local master = target:getMaster()
if target:isPlayer() and not master or master and master:isPlayer() then
if target:hasPlayerOwned() then
doTargetCombat(0, target, COMBAT_ICEDAMAGE, min, max, CONST_ME_NONE)
return true
end
Expand Down
9 changes: 4 additions & 5 deletions data/scripts/spells/monster/frozen_minion_heal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:setArea(createCombatArea(AREA_CIRCLE2X2))

function onTargetCreature(creature, target)
local min = 100
local max = 200
local master = target:getMaster()
if target:isPlayer() and not master or master and master:isPlayer() then
if target:hasPlayerOwned() then
return true
end


local min = 100
local max = 200
doTargetCombat(0, target, COMBAT_HEALING, min, max, CONST_ME_NONE)
return true
end
Expand Down
3 changes: 1 addition & 2 deletions data/scripts/spells/monster/frozen_minion_wave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ combat:setArea(createCombatArea(area))
function onTargetCreature(creature, target)
local min = 200
local max = 700
local master = target:getMaster()
if target:isPlayer() and not master or master and master:isPlayer() then
if target:hasPlayerOwned() then
doTargetCombat(0, target, COMBAT_ICEDAMAGE, min, max, CONST_ME_NONE)
return true
end
Expand Down
15 changes: 4 additions & 11 deletions data/scripts/spells/monster/heal_monsters.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
function onTargetCreature(creature, target)
local player = creature:getPlayer()
local min = 100
local max = 300
local master = target:getMaster()

if target:isPlayer() then
if target:hasPlayerOwned() then
return true
end

if master then
return true
end


local min = 100
local max = 300
doTargetCombatHealth(0, target, COMBAT_HEALING, min, max, CONST_ME_NONE)
return true
end
Expand Down
15 changes: 4 additions & 11 deletions data/scripts/spells/monster/heal_monsters_9x9.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
function onTargetCreature(creature, target)
local player = creature:getPlayer()
local min = 0
local max = 1000
local master = target:getMaster()

if target:isPlayer() then
if target:hasPlayerOwned() then
return true
end

if master then
return true
end


local min = 0
local max = 1000
doTargetCombatHealth(0, target, COMBAT_HEALING, min, max, CONST_ME_NONE)
return true
end
Expand Down
7 changes: 3 additions & 4 deletions data/scripts/spells/monster/icicle_heal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:setArea(createCombatArea(AREA_CIRCLE3X3))

function onTargetCreature(creature, target)
local min = 400
local max = 600
local master = target:getMaster()
if target:isPlayer() and not master or master and master:isPlayer() then
if target:hasPlayerOwned() then
return true
end

local min = 400
local max = 600
doTargetCombat(0, target, COMBAT_HEALING, min, max, CONST_ME_NONE)
return true
end
Expand Down
76 changes: 20 additions & 56 deletions src/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,6 @@ ConditionType_t Combat::DamageToConditionType(CombatType_t type)
}
}

bool Combat::isPlayerCombat(const Creature* target)
{
if (target->getPlayer()) {
return true;
}

if (target->isSummon() && target->getMaster()->getPlayer()) {
return true;
}

return false;
}

ReturnValue Combat::canTargetCreature(Player* attacker, Creature* target)
{
if (attacker == target) {
Expand All @@ -194,7 +181,7 @@ ReturnValue Combat::canTargetCreature(Player* attacker, Creature* target)
}

// nopvp-zone
if (isPlayerCombat(target)) {
if (target->hasPlayerOwned()) {
if (attacker->getZone() == ZONE_NOPVP) {
return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE;
}
Expand Down Expand Up @@ -317,19 +304,17 @@ ReturnValue Combat::canDoCombat(Creature* attacker, Creature* target)
}
}

if (attacker->isSummon()) {
if (const Player* masterAttackerPlayer = attacker->getMaster()->getPlayer()) {
if (masterAttackerPlayer->hasFlag(PlayerFlag_CannotAttackPlayer)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
}
if (const Player* masterAttackerPlayer = attacker->getPlayerMaster()) {
if (masterAttackerPlayer->hasFlag(PlayerFlag_CannotAttackPlayer)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
}

if (targetPlayer->getTile()->hasFlag(TILESTATE_NOPVPZONE)) {
return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE;
}
if (targetPlayer->getTile()->hasFlag(TILESTATE_NOPVPZONE)) {
return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE;
}

if (isProtected(masterAttackerPlayer, targetPlayer)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
}
if (isProtected(masterAttackerPlayer, targetPlayer)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
}
}
} else if (target->getMonster()) {
Expand All @@ -338,34 +323,21 @@ ReturnValue Combat::canDoCombat(Creature* attacker, Creature* target)
return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
}

if (target->isSummon() && target->getMaster()->getPlayer() && target->getZone() == ZONE_NOPVP) {
if (target->isPlayerSummon() && target->getZone() == ZONE_NOPVP) {
return RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE;
}
} else if (attacker->getMonster()) {
const Creature* targetMaster = target->getMaster();

if (!targetMaster || !targetMaster->getPlayer()) {
const Creature* attackerMaster = attacker->getMaster();

if (!attackerMaster || !attackerMaster->getPlayer()) {
return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
}
if (!target->isPlayerSummon() && !attacker->isPlayerSummon()) {
return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
}
}
}

if (g_game.getWorldType() == WORLD_TYPE_NO_PVP) {
if (attacker->getPlayer() || (attacker->isSummon() && attacker->getMaster()->getPlayer())) {
if (target->getPlayer()) {
if (!isInPvpZone(attacker, target)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER;
}
}

if (target->isSummon() && target->getMaster()->getPlayer()) {
if (!isInPvpZone(attacker, target)) {
return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
}
if (attacker->hasPlayerOwned() && target->hasPlayerOwned()) {
if (!isInPvpZone(attacker, target)) {
return target->getPlayer() ? RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
: RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE;
}
}
}
Expand Down Expand Up @@ -560,14 +532,7 @@ void Combat::combatTileEffects(const SpectatorVec& spectators, Creature* caster,
}

if (caster) {
Player* casterPlayer;
if (caster->isSummon()) {
casterPlayer = caster->getMaster()->getPlayer();
} else {
casterPlayer = caster->getPlayer();
}

if (casterPlayer) {
if (Player* casterPlayer = caster->getPlayerOwned()) {
if (g_game.getWorldType() == WORLD_TYPE_NO_PVP || tile->hasFlag(TILESTATE_NOPVPZONE)) {
if (itemId == ITEM_FIREFIELD_PVP_FULL) {
itemId = ITEM_FIREFIELD_NOPVP;
Expand Down Expand Up @@ -1403,9 +1368,8 @@ void MagicField::onStepInField(Creature* creature)
bool harmfulField = true;

if (g_game.getWorldType() == WORLD_TYPE_NO_PVP || getTile()->hasFlag(TILESTATE_NOPVPZONE)) {
Creature* owner = g_game.getCreatureByID(ownerId);
if (owner) {
if (owner->getPlayer() || (owner->isSummon() && owner->getMaster()->getPlayer())) {
if (Creature* owner = g_game.getCreatureByID(ownerId)) {
if (owner->hasPlayerOwned()) {
harmfulField = false;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/combat.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class Combat

static bool isInPvpZone(const Creature* attacker, const Creature* target);
static bool isProtected(const Player* attacker, const Player* target);
static bool isPlayerCombat(const Creature* target);
static CombatType_t ConditionToDamageType(ConditionType_t type);
static ConditionType_t DamageToConditionType(CombatType_t type);
static ReturnValue canTargetCreature(Player* attacker, Creature* target);
Expand Down
10 changes: 5 additions & 5 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ void Creature::goToFollowCreature()
getPathSearchParams(followCreature, fpp);

Monster* monster = getMonster();
if (monster && !monster->getMaster() && (monster->isFleeing() || fpp.maxTargetDist > 1)) {
if (monster && !monster->isSummon() && (monster->isFleeing() || fpp.maxTargetDist > 1)) {
Direction dir = DIRECTION_NONE;

if (monster->isFleeing()) {
Expand Down Expand Up @@ -1463,11 +1463,11 @@ int64_t Creature::getStepDuration() const
double duration = std::floor(1000 * groundSpeed / calculatedStepSpeed);
int64_t stepDuration = std::ceil(duration / 50) * 50;

const Monster* monster = getMonster();
if (monster && monster->isTargetNearby() && !monster->isFleeing() && !monster->getMaster()) {
stepDuration *= 2;
if (const Monster* monster = getMonster()) {
if (monster->isTargetNearby() && !monster->isFleeing()) {
stepDuration *= 2;
}
}

return stepDuration;
}

Expand Down
Loading
Loading