Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Trust: changed way to generate the list of trust. #6352

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion scripts/globals/spells/trust/Shantotto_II.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ function onMagicCastingCheck(caster,target,spell)
end

function onSpellCast(caster,target,spell)
-- caster:spawnTrust(1019)
caster:spawnTrust(1019)
return 0
end
16 changes: 16 additions & 0 deletions scripts/globals/spells/trust/kupipi.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-----------------------------------------
-- Spell: Kupipi
-----------------------------------------
require("scripts/globals/trust");
-----------------------------------------

function onMagicCastingCheck(caster,target,spell)
return 0
end

function onSpellCast(caster,target,spell)
-- Todo: put Trusts's spawn in dialog here or in entity script?
-- Todo: automate entity spawn in core for trust spells?
caster:spawnTrust(898)
return 0
end
16 changes: 16 additions & 0 deletions scripts/globals/spells/trust/naji.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-----------------------------------------
-- Spell: Naji
-----------------------------------------
require("scripts/globals/trust");
-----------------------------------------

function onMagicCastingCheck(caster,target,spell)
return 0
end

function onSpellCast(caster,target,spell)
-- Todo: put Trusts's spawn in dialog here or in entity script?
Omnione marked this conversation as resolved.
Show resolved Hide resolved
-- Todo: automate entity spawn in core for trust spells?
caster:spawnTrust(897)
return 0
end
4 changes: 2 additions & 2 deletions scripts/globals/spells/trust/shantotto.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-----------------------------------------
-- Spell: Shantotto
-----------------------------------------
-- require("scripts/globals/trust");
require("scripts/globals/trust");
-----------------------------------------

function onMagicCastingCheck(caster,target,spell)
Expand All @@ -11,6 +11,6 @@ end
function onSpellCast(caster,target,spell)
-- Todo: put Trusts's spawn in dialog here or in entity script?
-- Todo: automate entity spawn in core for trust spells?
caster:spawnTrust(75) -- see pet_list.sql, this should be 896 but the pet list won't let me do that
caster:spawnTrust(896)
return 0
end
16 changes: 16 additions & 0 deletions scripts/globals/spells/trust/trion.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-----------------------------------------
-- Spell: Trion
-----------------------------------------
require("scripts/globals/trust");
-----------------------------------------

function onMagicCastingCheck(caster,target,spell)
return 0
end

function onSpellCast(caster,target,spell)
-- Todo: put Trusts's spawn in dialog here or in entity script?
-- Todo: automate entity spawn in core for trust spells?
caster:spawnTrust(905)
return 0
end
22 changes: 11 additions & 11 deletions sql/mob_pools.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5953,16 +5953,16 @@ INSERT INTO `mob_pools` VALUES (5892,'Euryale','Euryale',171,0x06007106000000000
INSERT INTO `mob_pools` VALUES (5893,'Gloombound_Lurker','Gloombound_Lurker',221,0x0000230200000000000000000000000000000000,6,6,5,360,100,0,1,0,1,2,7,0,0,155,0,0,0,1,0,0);
INSERT INTO `mob_pools` VALUES (5894,'Lesath','Lesath',217,0x00001C0100000000000000000000000000000000,1,1,7,280,100,0,1,0,1,2,7,0,238,141,0,0,0,1,0,370);
INSERT INTO `mob_pools` VALUES (5895,'Donggu','Donggu',116,0x0000780100000000000000000000000000000000,1,1,11,240,100,0,0,0,1,2,7,0,0,3,0,0,0,1,0,116);
INSERT INTO `mob_pools` VALUES (5896,'Shantotto','Shantotto',153,0x0000B80B00000000000000000000000000000000,4,5,2,240,100,0,2,0,0,0,0,32,0,3,0,0,276,1,0,750);
-- INSERT INTO `mob_pools` VALUES (5897,'naji',
-- INSERT INTO `mob_pools` VALUES (5898,'kupipi',
-- INSERT INTO `mob_pools` VALUES (5899,'excenmille',
-- INSERT INTO `mob_pools` VALUES (5900,'ayame',
-- INSERT INTO `mob_pools` VALUES (5901,'nanaa_mihgo',
-- INSERT INTO `mob_pools` VALUES (5902,'curilla',
-- INSERT INTO `mob_pools` VALUES (5903,'volker',
-- INSERT INTO `mob_pools` VALUES (5904,'ajido-marujido',
-- INSERT INTO `mob_pools` VALUES (5905,'trion',
INSERT INTO `mob_pools` VALUES (5896,'Shantotto','shantotto',153,0x0000B80B00000000000000000000000000000000,4,5,2,240,100,0,2,0,0,0,0,32,0,3,0,0,276,1,0,750);
INSERT INTO `mob_pools` VALUES (5897,'Naji','naji',149,0x0000B90B00000000000000000000000000000000,4,5,2,240,100,0,2,0,0,0,0,32,0,3,0,0,276,1,0,750);
INSERT INTO `mob_pools` VALUES (5898,'Kupipi','kupipi',153,0x0000BA0B00000000000000000000000000000000,3,0,11,230,100,2,0,0,0,0,0,32,0,3,0,1,3,1,0,3);
INSERT INTO `mob_pools` VALUES (5899,'Excenmille','excenmille',145,0x0000BB0B00000000000000000000000000000000,7,0,8,390,100,0,0,0,0,0,0,32,0,3,0,0,4,1,0,4);
INSERT INTO `mob_pools` VALUES (5900,'Ayame','ayame',149,0x0000BC0B00000000000000000000000000000000,12,0,10,440,100,0,0,0,0,0,0,32,0,3,0,0,0,1,0,5);
INSERT INTO `mob_pools` VALUES (5901,'Nanaa Mihgo','nanaa_mihgo',152,0x0000BD0B00000000000000000000000000000000,6,0,2,190,100,0,0,0,0,0,0,32,0,3,0,0,0,1,0,6);
INSERT INTO `mob_pools` VALUES (5902,'Curilla','curilla',145,0x0000BE0B00000000000000000000000000000000,7,0,3,240,100,0,0,0,0,0,0,32,0,3,0,0,7,1,0,7);
INSERT INTO `mob_pools` VALUES (5903,'Volker','volker',149,0x0000BF0B00000000000000000000000000000000,1,0,3,240,100,0,0,0,0,0,0,32,0,3,0,0,8,1,0,8);
INSERT INTO `mob_pools` VALUES (5904,'Ajido-marujido','ajido-marujido',153,0x0000C00B00000000000000000000000000000000,4,5,1,400,100,0,0,0,0,0,0,32,0,3,0,1,9,1,0,0);
INSERT INTO `mob_pools` VALUES (5905,'Trion','trion',145,0x0000C10B00000000000000000000000000000000,7,1,3,240,100,0,0,0,0,0,0,32,0,3,0,0,10,1,0,10);
-- INSERT INTO `mob_pools` VALUES (5906,'zeid',
-- INSERT INTO `mob_pools` VALUES (5907,'lion',
-- INSERT INTO `mob_pools` VALUES (5908,'tenzen',
Expand Down Expand Up @@ -6076,7 +6076,7 @@ INSERT INTO `mob_pools` VALUES (5896,'Shantotto','Shantotto',153,0x0000B80B00000
-- INSERT INTO `mob_pools` VALUES (6016,'ingrid_ii',
-- INSERT INTO `mob_pools` VALUES (6017,'arciela_ii',
-- INSERT INTO `mob_pools` VALUES (6018,'iroha_ii',
INSERT INTO `mob_pools` VALUES (6019,'shantotto_ii','shantotto_ii',153,0x0000260C00000000000000000000000000000000,4,5,2,240,100,0,2,0,0,0,0,32,0,3,0,0,276,1,0,750);
INSERT INTO `mob_pools` VALUES (6019,'Shantotto II','shantotto_ii',153,0x0000260C00000000000000000000000000000000,4,5,2,240,100,0,2,0,0,0,0,32,0,3,0,0,276,1,0,750);
-- Reserved for future Trust 6020
-- Reserved for future Trust 6021
-- Reserved for future Trust 6022
Expand Down
4 changes: 1 addition & 3 deletions sql/pet_list.sql
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,4 @@ INSERT INTO `pet_list` VALUES (72, 'StormwakerFrame', 5127, 1, 99, 0, 0);
-- INSERT INTO `pet_list` VALUES (73, 'AdventuringFellow', 0, 1, 99, 0, 0);
-- 74 is Chocobo in the enum..


-- trusts.. TODO: Make trusts not use petlist at all.
INSERT INTO `pet_list` VALUES (75, 'Shantotto', 5896, 1, 99, 0, 0);
-- INSERT INTO `pet_list` VALUES (75, 'Trust', 0, 1, 99, 0, 0);
67 changes: 59 additions & 8 deletions src/map/ai/controllers/trust_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ This file is part of DarkStar-server source code.

#include "../ai_container.h"
#include "../../status_effect_container.h"
#include "../../enmity_container.h"
#include "../../ai/states/despawn_state.h"
#include "../../entities/charentity.h"
#include "../../entities/trustentity.h"
#include "../../packets/char.h"
#include "../../../common/utils.h"
#include "../../lua/lua_baseentity.h"

CTrustController::CTrustController(CCharEntity* PChar, CTrustEntity* PTrust) : CController(PTrust)
{
Expand All @@ -51,17 +53,38 @@ void CTrustController::Despawn()
if (POwner->PMaster)
{
POwner->PMaster = nullptr;
POwner->PAI->Internal_Despawn();
}
CController::Despawn();
//CController::Despawn();
}

void CTrustController::Tick(time_point tick)
{
m_Tick = tick;

if (!POwner->PMaster)
return;

if (POwner->PAI->IsEngaged())
{
DoCombatTick(tick);
auto PTarget{ POwner->GetBattleTarget() };

if (PTarget)
{
auto PMob = static_cast<CMobEntity*>(PTarget);

if (PMob->PEnmityContainer->GetHighestEnmity() != nullptr)
{
if (PMob->PEnmityContainer->HasID(POwner->PMaster->id))
{
DoCombatTick(tick);
}
else if (!POwner->isDead())
{
DoRoamTick(tick);
}
}
}
}
else if (!POwner->isDead())
{
Expand All @@ -75,11 +98,14 @@ void CTrustController::DoCombatTick(time_point tick)
{
POwner->PAI->Internal_Disengage();
}

if (POwner->PMaster->GetBattleTargetID() != POwner->GetBattleTargetID())
{
POwner->PAI->Internal_ChangeTarget(POwner->PMaster->GetBattleTargetID());
}

auto PTarget{ POwner->GetBattleTarget() };

if (PTarget)
{
if (POwner->PAI->CanFollowPath())
Expand All @@ -105,17 +131,42 @@ void CTrustController::DoRoamTick(time_point tick)
POwner->PAI->Internal_Engage(POwner->PMaster->GetBattleTargetID());
}

float currentDistance = distance(POwner->loc.p, POwner->PMaster->loc.p);
auto master = static_cast<CCharEntity*>(POwner->PMaster);
auto PTrust = static_cast<CTrustEntity*>(POwner);
uint8 currentPartyPos = master->TrustPartyPosition(PTrust);
float currentDistance = 0;

if (currentDistance > RoamDistance)
if (currentPartyPos == 0)
{
if (currentDistance < 35.0f && POwner->PAI->PathFind->PathAround(POwner->PMaster->loc.p, 2.0f, PATHFLAG_RUN | PATHFLAG_WALLHACK))
currentDistance = distance(POwner->loc.p, POwner->PMaster->loc.p);

if (currentDistance > RoamDistance)
{
POwner->PAI->PathFind->FollowPath();
if (currentDistance < 35.0f && PTrust->PAI->PathFind->PathTo(POwner->PMaster->loc.p, PATHFLAG_RUN | PATHFLAG_WALLHACK))
{
PTrust->PAI->PathFind->FollowPath();
}
else if (POwner->GetSpeed() > 0)
{
PTrust->PAI->PathFind->WarpTo(POwner->PMaster->loc.p, RoamDistance);
}
}
else if (POwner->GetSpeed() > 0)
}
else if(currentPartyPos > 0)
{
CBattleEntity* PFollow = (CBattleEntity*)master->PTrusts.at(currentPartyPos - 1);
currentDistance = distance(PTrust->loc.p, PFollow->loc.p);

if (currentDistance > 2.0f)
{
POwner->PAI->PathFind->WarpTo(POwner->PMaster->loc.p, RoamDistance);
if (currentDistance < 35.0f && PTrust->PAI->PathFind->PathTo(PFollow->loc.p, PATHFLAG_RUN | PATHFLAG_WALLHACK))
{
PTrust->PAI->PathFind->FollowPath();
}
else if (POwner->GetSpeed() > 0)
{
PTrust->PAI->PathFind->WarpTo(PFollow->loc.p, RoamDistance);
}
}
}
}
14 changes: 9 additions & 5 deletions src/map/ai/controllers/trust_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,26 @@ class CTrustEntity;
class CTrustController : public CController
{
public:

CTrustController(CCharEntity*, CTrustEntity*);
CBattleEntity* PTarget{ nullptr };
virtual ~CTrustController();
static constexpr float RoamDistance{ 5.5f };
virtual void DoCombatTick(time_point tick);
virtual void DoRoamTick(time_point tick);

protected:

virtual void Tick(time_point) override;
virtual void Despawn() override;

virtual bool Cast(uint16 targid, SpellID spellid) override { return false; }
virtual bool ChangeTarget(uint16 targid) override { return false; }
virtual bool WeaponSkill(uint16 targid, uint16 wsid) override { return false; }

virtual bool Ability(uint16 targid, uint16 abilityid) override { return false; }

private:
static constexpr float RoamDistance{ 2.1f };
void DoCombatTick(time_point tick);
void DoRoamTick(time_point tick);


};

#endif // _TRUSTCONTROLLER
23 changes: 22 additions & 1 deletion src/map/entities/charentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,17 +478,38 @@ void CCharEntity::RemoveTrust(CTrustEntity* PTrust)
return;

auto trustIt = std::remove_if(PTrusts.begin(), PTrusts.end(), [PTrust](auto trust) { return PTrust == trust; });

if (trustIt != PTrusts.end())
{
PTrust->PAI->Despawn();
PTrusts.erase(trustIt);
}

if (PParty != nullptr)
{
PParty->ReloadParty();
if (PTrusts.size() < 1 && PParty->members.size() == 1)
{
PParty->DisbandParty();
}
else
{
PParty->ReloadParty();
}
}
}

uint8 CCharEntity::TrustPartyPosition(CTrustEntity* PTrust)
{
for (uint8 i = 0; i < PTrusts.size(); i++)
{
if (PTrusts.at(i)->id == PTrust->id)
{
return i;
}
}
return 0;
}

void CCharEntity::ClearTrusts()
{
if (PTrusts.size() == 0)
Expand Down
25 changes: 14 additions & 11 deletions src/map/entities/charentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,20 @@ class CCharEntity : public CBattleEntity

UnlockedAttachments_t m_unlockedAttachments; // Unlocked Automaton Attachments (1 bit per attachment)
CAutomatonEntity* PAutomaton; // Automaton statistics
CTrustEntity* PTrust; // Trust statistics

std::vector<CTrustEntity*> PTrusts; // Active trusts


// Эти миссии не нуждаются в списке пройденных, т.к. клиент автоматически
// отображает более ранние миссии выплненными
// These missions do not need a list of completed, because client automatically
// displays earlier missions completed

uint16 m_copCurrent; // текущая миссия Chains of Promathia
uint16 m_acpCurrent; // текущая миссия A Crystalline Prophecy
uint16 m_mkeCurrent; // текущая миссия A Moogle Kupo d'Etat
uint16 m_asaCurrent; // текущая миссия A Shantotto Ascension
uint16 m_copCurrent; // current mission of Chains of Promathia
uint16 m_acpCurrent; // current mission of A Crystalline Prophecy
uint16 m_mkeCurrent; // current mission of A Moogle Kupo d'Etat
uint16 m_asaCurrent; // current mission of A Shantotto Ascension

// TODO: половина этого массива должна храниться в char_vars, а не здесь, т.к. эта информация не отображается в интерфейсе клиента и сервер не проводит с ними никаких операций
// TODO: half of this array should be stored in char_vars, and not here, because this information is not displayed in the client interface and the server does not perform any operations with them
Omnione marked this conversation as resolved.
Show resolved Hide resolved

//currency_t m_currency; // conquest points, imperial standing points etc
Teleport_t teleport; // Outposts, Runic Portals, Homepoints, Survival Guides, Maws, etc
Expand Down Expand Up @@ -260,10 +261,11 @@ class CCharEntity : public CBattleEntity

CBaseEntity* PWideScanTarget; // wide scane цель

SpawnIDList_t SpawnPCList; // список видимых персонажей
SpawnIDList_t SpawnMOBList; // список видимых монстров
SpawnIDList_t SpawnPETList; // список видимых питомцев
SpawnIDList_t SpawnNPCList; // список видимых npc
SpawnIDList_t SpawnPCList; // list of visible characters
SpawnIDList_t SpawnMOBList; // list of visible monsters
SpawnIDList_t SpawnPETList; // list of visible pets
SpawnIDList_t SpawnTRUSTList; // list of visible trust
SpawnIDList_t SpawnNPCList; // list of visible npc's

void SetName(int8* name); // устанавливаем имя персонажа (имя ограничивается 15-ю символами)

Expand Down Expand Up @@ -328,6 +330,7 @@ class CCharEntity : public CBattleEntity
bool ReloadParty();
void ClearTrusts();
void RemoveTrust(CTrustEntity*);
uint8 TrustPartyPosition(CTrustEntity* PTrust);

virtual void Tick(time_point) override;
void PostTick() override;
Expand Down
4 changes: 2 additions & 2 deletions src/map/entities/trustentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class CTrustEntity : public CMobEntity
public:
CTrustEntity(CCharEntity*);
~CTrustEntity();
uint8 m_Element;
uint32 m_PetID;
uint32 m_TrustID;
uint16 m_PartyPosition;

virtual void PostTick() override;
virtual void FadeOut() override;
Expand Down
Loading