Skip to content

Commit

Permalink
Improve drawin specification with local vars
Browse files Browse the repository at this point in the history
  • Loading branch information
TracentEden committed Jul 14, 2024
1 parent 46c7655 commit 35b8b95
Show file tree
Hide file tree
Showing 24 changed files with 162 additions and 71 deletions.
2 changes: 1 addition & 1 deletion scripts/enum/mob_mod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ xi.mobMod =
HP_HEAL_CHANCE = 9, -- can cast cures below this HP %
SUBLINK = 10, -- sub link group
LINK_RADIUS = 11, -- link radius
DRAW_IN = 12, -- 1 - player draw in, 2 - alliance draw in -- only add as a spawn mod!
DRAW_IN = 12, -- 1 - player/pet draw in, only add as a spawn mod, also see local var options like [DrawIn]IncludeAlliance=1 for alliance drawin
SEVERE_SPELL_CHANCE = 13, -- % chance to use a severe spell like death or impact
SKILL_LIST = 14, -- uses given mob skill list
MUG_GIL = 15, -- amount gil carried for mugging
Expand Down
3 changes: 2 additions & 1 deletion scripts/zones/Attohwa_Chasm/mobs/Tiamat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ end

entity.onMobInitialize = function(mob)
mob:setCarefulPathing(true)
mob:setMobMod(xi.mobMod.DRAW_IN, 8)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]TriggerDist', 8)
-- Reset animation so it starts grounded.
mob:setMobSkillAttack(0)
mob:setAnimationSub(0)
Expand Down
2 changes: 2 additions & 0 deletions scripts/zones/Behemoths_Dominion/mobs/King_Behemoth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ local entity = {}
entity.onMobInitialize = function(mob)
mob:setMobMod(xi.mobMod.ADD_EFFECT, 1)
mob:setMobMod(xi.mobMod.MAGIC_COOL, 60)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]TriggerDist', 25)
mob:setLocalVar('[rage]timer', 3600) -- 60 minutes

-- Despawn the ???
Expand Down
5 changes: 5 additions & 0 deletions scripts/zones/Dragons_Aery/mobs/Fafnir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ mixins = { require('scripts/mixins/rage') }
-----------------------------------
local entity = {}

entity.onMobInitialize = function(mob)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]TriggerDist', 20)
mob:setLocalVar('[rage]timer', 3600) -- 60 minutes
mob:setMobMod(xi.mobMod.WEAPON_BONUS, 50) -- Level 90 + 50 = 140 Base Weapon Damage

Expand Down
6 changes: 5 additions & 1 deletion scripts/zones/FeiYin/mobs/Capricious_Cassie.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ mixins = { require('scripts/mixins/rage') }
local entity = {}

entity.onMobInitialize = function(mob)
mob:setMobMod(xi.mobMod.DRAW_IN, 2)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]IncludeAlliance', 1)
end

entity.onMobDeath = function(mob, player, optParams)
Expand Down
8 changes: 8 additions & 0 deletions scripts/zones/King_Ranperres_Tomb/mobs/Vrtra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ local entity = {}

local offsets = { 1, 3, 5, 2, 4, 6 }

entity.onMobInitialize = function(mob)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]TriggerDist', 15)
end

entity.onMobEngage = function(mob, target)
-- Reset the onMobFight variables
mob:setLocalVar('spawnTime', 0)
Expand Down
3 changes: 2 additions & 1 deletion scripts/zones/Mamook/mobs/Gulool_Ja_Ja.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ local entity = {}

entity.onMobSpawn = function(mob)
mob:setMod(xi.mod.DOUBLE_ATTACK, 20)
mob:setMobMod(xi.mobMod.DRAW_IN, 2)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
mob:setLocalVar('[DrawIn]IncludeAlliance', 1)
end

entity.onMobEngage = function(mob, target)
Expand Down
4 changes: 3 additions & 1 deletion scripts/zones/Phomiuna_Aqueducts/mobs/Minotaur.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ mixins = { require('scripts/mixins/fomor_hate') }
local entity = {}

entity.onMobInitialize = function(mob)
mob:setMobMod(xi.mobMod.DRAW_IN, 15)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]IncludeAlliance', 1)
mob:setLocalVar('[DrawIn]TriggerDist', 15)
mob:setLocalVar('fomorHateAdj', 2)
end

Expand Down
3 changes: 2 additions & 1 deletion scripts/zones/Riverne-Site_A01/mobs/Ouryu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
local entity = {}

entity.onMobInitialize = function(mob)
mob:setMobMod(xi.mobMod.DRAW_IN, 15)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobSpawn = function(mob, player, optParams)
mob:setLocalVar('[DrawIn]TriggerDist', 15)
mob:setMobMod(xi.mobMod.WEAPON_BONUS, 60) -- Level 85 + 60 = 145 Base Weapon Damage
end

Expand Down
6 changes: 5 additions & 1 deletion scripts/zones/The_Boyahda_Tree/mobs/Voluptuous_Vivian.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ mixins = { require('scripts/mixins/job_special') }
local entity = {}

entity.onMobInitialize = function(mob)
mob:setMobMod(xi.mobMod.DRAW_IN, 2)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]IncludeAlliance', 1)
end

entity.onMobDeath = function(mob, player, optParams)
Expand Down
3 changes: 2 additions & 1 deletion scripts/zones/Uleguerand_Range/mobs/Jormungand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ end

entity.onMobInitialize = function(mob)
mob:setCarefulPathing(true)
mob:setMobMod(xi.mobMod.DRAW_IN, 15)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]TriggerDist', 15)
-- Reset animation so it starts grounded.
mob:setMobSkillAttack(0)
mob:setAnimationSub(0)
Expand Down
4 changes: 4 additions & 0 deletions scripts/zones/Waughroon_Shrine/mobs/Dark_Dragon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ entity.onMobInitialize = function(mob)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]TriggerDist', 25)
end

entity.onMobDeath = function(mob, player, optParams)
player:addTitle(xi.title.DARK_DRAGON_SLAYER)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ local entity = {}

entity.onMobInitialize = function(mob)
mob:setMobMod(xi.mobMod.ADD_EFFECT, 1)
mob:setMobMod(xi.mobMod.DRAW_IN, 2)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]TriggerDist', 15)
mob:setLocalVar('[DrawIn]IncludeAlliance', 1)
end

entity.onMobDrawIn = function(mob, target)
Expand Down
6 changes: 6 additions & 0 deletions scripts/zones/Xarcabard/mobs/Boreal_Coeurl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,17 @@ entity.onMobRoam = function(mob)
end
end

entity.onMobInitialize = function(mob)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobEngage = function(mob)
mob:setSpeed(baseSpeed)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]TriggerDist', 15)
mob:setLocalVar('[DrawIn]IncludeAlliance', 1)
mob:setSpeed(baseSpeed)
-- Failsafe to make sure NPC is down when NM is up
if xi.settings.main.OLDSCHOOL_G2 then
Expand Down
6 changes: 6 additions & 0 deletions scripts/zones/Xarcabard/mobs/Boreal_Hound.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,17 @@ entity.onMobRoam = function(mob)
end
end

entity.onMobInitialize = function(mob)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobEngage = function(mob)
mob:setSpeed(baseSpeed)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]TriggerDist', 15)
mob:setLocalVar('[DrawIn]IncludeAlliance', 1)
mob:setSpeed(baseSpeed)
-- Failsafe to make sure NPC is down when NM is up
if xi.settings.main.OLDSCHOOL_G2 then
Expand Down
6 changes: 6 additions & 0 deletions scripts/zones/Xarcabard/mobs/Boreal_Tiger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ entity.onMobEngage = function(mob)
mob:setSpeed(baseSpeed)
end

entity.onMobInitialize = function(mob)
mob:setMobMod(xi.mobMod.DRAW_IN, 1)
end

entity.onMobSpawn = function(mob)
mob:setLocalVar('[DrawIn]TriggerDist', 15)
mob:setLocalVar('[DrawIn]IncludeAlliance', 1)
mob:setSpeed(baseSpeed)
-- Failsafe to make sure NPC is down when NM is up
if xi.settings.main.OLDSCHOOL_G2 then
Expand Down
3 changes: 0 additions & 3 deletions sql/mob_pool_mods.sql
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ INSERT INTO `mob_pool_mods` VALUES (820,368,10,0); -- REGAIN: 10
-- Darksteel Golem
INSERT INTO `mob_pool_mods` VALUES (906,4,4,1); -- SIGHT_RANGE: 4

-- Dark Dragon
INSERT INTO `mob_pool_mods` VALUES (912,12,25,1); -- DRAW_IN: 25

-- Dea
INSERT INTO `mob_pool_mods` VALUES (930,370,15,0); -- REGEN: 15

Expand Down
14 changes: 0 additions & 14 deletions sql/mob_spawn_mods.sql
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,11 @@ INSERT INTO `mob_spawn_mods` VALUES (17235987,2,2765,1); -- GIL_MAX: 2765
INSERT INTO `mob_spawn_mods` VALUES (17236201,55,180,1); -- IDLE_DESPAWN: 180

-- Boreal Hound
INSERT INTO `mob_spawn_mods` VALUES (17236202,12,15,1); -- DRAW_IN: 15
INSERT INTO `mob_spawn_mods` VALUES (17236202,160,50,0); -- DMG: 50

-- Boreal Coeurl
INSERT INTO `mob_spawn_mods` VALUES (17236203,12,15,1); -- DRAW_IN: 15
INSERT INTO `mob_spawn_mods` VALUES (17236203,23,8,1); -- IMMUNITY: 8

-- Boreal Tiger
INSERT INTO `mob_spawn_mods` VALUES (17236204,12,15,1); -- DRAW_IN: 15

-- Koenigstiger
INSERT INTO `mob_spawn_mods` VALUES (17236205,55,240,1); -- IDLE_DESPAWN: 240

Expand Down Expand Up @@ -399,9 +394,6 @@ INSERT INTO `mob_spawn_mods` VALUES (17285545,55,300,1); -- IDLE_DESPAWN: 300
-- Kappa Biwa
INSERT INTO `mob_spawn_mods` VALUES (17285546,55,150,1); -- IDLE_DESPAWN: 150

-- King Vinegarroon
INSERT INTO `mob_spawn_mods` VALUES (17289575,12,15,1); -- DRAW_IN: 15

-- Eastern Sphinx
INSERT INTO `mob_spawn_mods` VALUES (17289654,55,168,1); -- IDLE_DESPAWN: 168

Expand All @@ -412,9 +404,6 @@ INSERT INTO `mob_spawn_mods` VALUES (17289655,55,168,1); -- IDLE_DESPAWN: 168
INSERT INTO `mob_spawn_mods` VALUES (17293486,31,5,1); -- ROAM_DISTANCE: 5
INSERT INTO `mob_spawn_mods` VALUES (17293486,51,1,1); -- ROAM_TURNS: 1

-- King Behemoth
INSERT INTO `mob_spawn_mods` VALUES (17297441,12,25,1); -- DRAW_IN: 25

-- Picklix Longindex
INSERT INTO `mob_spawn_mods` VALUES (17297446,55,180,1); -- IDLE_DESPAWN: 180

Expand Down Expand Up @@ -827,9 +816,6 @@ INSERT INTO `mob_spawn_mods` VALUES (17404337,55,288,1); -- IDLE_DESPAWN: 288
-- Beet Leafhopper
INSERT INTO `mob_spawn_mods` VALUES (17404338,55,120,1); -- IDLE_DESPAWN: 120

-- Fafnir
INSERT INTO `mob_spawn_mods` VALUES (17408018,12,20,1); -- DRAW_IN: 20

-- Gerwitz'S Scythe
INSERT INTO `mob_spawn_mods` VALUES (17420629,55,300,1); -- IDLE_DESPAWN: 300

Expand Down
27 changes: 25 additions & 2 deletions src/map/ai/controllers/mob_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,9 @@ void CMobController::Move()
// TODO: can this be moved to scripts entirely?
if (PMob->getMobMod(MOBMOD_DRAW_IN) > 0)
{
if (currentDistance >= PMob->GetMeleeRange() * 2 && battleutils::DrawIn(PTarget, PMob, PMob->GetMeleeRange() - 0.2f))
bool didDrawin = HandleDrawin(currentDistance);
if (didDrawin)
{
FaceTarget();
return;
}
}
Expand Down Expand Up @@ -1408,3 +1408,26 @@ bool CMobController::IsSpellReady(float currentDistance)

return (m_Tick >= m_LastMagicTime + std::chrono::milliseconds(PMob->getBigMobMod(MOBMOD_MAGIC_COOL) - bonusTime));
}

bool CMobController::HandleDrawin(float currentDistance)
{
// get specific draw-in settings that can be set on any given mob otherwise use default values
uint32 drawInTriggerDistance = PMob->GetLocalVar("[DrawIn]TriggerDist") > 0 ? PMob->GetLocalVar("[DrawIn]TriggerDist") : PMob->GetMeleeRange() * 2;
uint32 drawInMaxDistance = PMob->GetLocalVar("[DrawIn]MaxDist") > 0 ? PMob->GetLocalVar("[DrawIn]MaxDist") : std::numeric_limits<int16>::max();
bool includeAlliance = PMob->GetLocalVar("[DrawIn]IncludeAlliance") > 0 ? true : false;
bool toFrontOfMob = PMob->GetLocalVar("[DrawIn]ToFrontOfMob") > 0 ? true : false;

bool didDrawin = false;

if (currentDistance >= drawInTriggerDistance)
{
bool didDrawin = battleutils::DrawIn(PTarget, PMob, PMob->GetMeleeRange() - 0.2f, drawInMaxDistance, includeAlliance, toFrontOfMob);

if (didDrawin)
{
FaceTarget();
}
}

return didDrawin;
}
1 change: 1 addition & 0 deletions src/map/ai/controllers/mob_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class CMobController : public CController
bool CanMoveForward(float currentDistance);
bool IsSpecialSkillReady(float currentDistance);
bool IsSpellReady(float currentDistance);
bool HandleDrawin(float currentDistance);

CBattleEntity* PTarget{ nullptr };

Expand Down
Loading

0 comments on commit 35b8b95

Please sign in to comment.