1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "server_share/msg_brick_service.h"
23 #include "game_share/tick_event_handler.h"
24 #include "server_share/effect_message.h"
26 #include "combat_interface.h"
28 #include "ai_entity_physical.h"
29 #include "ai_entity_physical_inline.h"
30 #include "ai_instance.h"
32 #include "ai_profile_npc.h"
34 using namespace NLMISC
;
35 using namespace NLNET
;
37 using namespace EFFECT_FAMILIES
;
40 std::list
<CCombatInterface::CEvent
> CCombatInterface::_events
;
42 static bool verboseLog
=false;
46 #define LOG if (!verboseLog) {} else nlinfo
48 static void cbServiceUpEGS( const string
& serviceName
, NLNET::TServiceId serviceId
, void * )
50 LOG("Combat Interface: EGS service mirror up");
52 // ask the brick service to give me event reports
53 CMessage
msgRegister("REGISTER_AI_EVENT_REPORTS");
54 sendMessageViaMirror ("EGS", msgRegister
);
57 void CCombatInterface::init()
59 LOG("Combat Interface: init()");
61 // register the incoming transport classes
62 TRANSPORT_CLASS_REGISTER(CBSAIEventReportMsg
);
63 TRANSPORT_CLASS_REGISTER(CEGSExecuteMsg
);
67 // setup service up callbacks
68 CMirrors::Mirror
.setServiceMirrorUpCallback( "EGS", cbServiceUpEGS
, 0);
71 void CCombatInterface::release()
73 LOG("Combat Interface: release()");
77 void CBSAIEventReportMsg::callback(const std::string
&name
, NLNET::TServiceId id
)
79 CCombatInterface::CEvent event
;
81 for (uint i
=0;i
<Originator
.size();i
++)
83 uint8 actionType
=ActionType
[i
];
84 if ( ( actionType
!=ACTNATURE::FIGHT
85 && actionType
!=ACTNATURE::OFFENSIVE_MAGIC
86 && actionType
!=ACTNATURE::CURATIVE_MAGIC
)
90 event
._originatorRow
= Originator
[i
];
91 event
._targetRow
= Target
[i
];
92 event
._weight
= AggroAdd
[i
];
93 clamp(event
._weight
,-1,+1);
94 event
._nature
= (ACTNATURE::TActionNature
)actionType
;
96 CCombatInterface::_events
.push_back(event
);
101 NLMISC_COMMAND(verboseCombatLog
,"Turn on or off or check the state of verbose combat logging","")
107 StrToBool (verboseLog
, args
[0]);
109 log
.displayNL("verboseCombatLogging is %s",verboseLog
?"ON":"OFF");
113 //-----------------------------------------------
115 //-----------------------------------------------
117 //void cbChangeMode( CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
120 // msgin.serial( row );
122 // // read the new Mode
123 // MBEHAV::TMode mode;
124 // msgin.serial( mode );
126 // CAIEntityPhysical *phys=CAIS::getEntityPhysical(row);
129 // && phys->getRyzomType()!=RYZOMID::player
130 // && phys->isAlive() )
132 // static_cast<CModEntityPhysical*>(phys)->setModeStruct(mode);
135 //} // cbChangeMode //
137 void CAddEffectsMessage::callback (const std::string
&name
, NLNET::TServiceId id
)
139 for (uint32 i
=0;i
<Entities
.size();i
++)
141 CAIEntityPhysical
*phys
=CAIS::instance().getEntityPhysical(Entities
[i
]);
145 switch ((TEffectFamily
)Families
[i
])
173 void CRemoveEffectsMessage::callback (const std::string
&name
, NLNET::TServiceId id
)
175 for (uint32 i
=0;i
<Entities
.size();i
++)
177 CAIEntityPhysical
*phys
=CAIS::instance().getEntityPhysical(Entities
[i
]);
181 switch ((TEffectFamily
)Families
[i
])
187 if(!phys
->isStuned())
189 CSpawnBot
* spawnBot
= dynamic_cast<CSpawnBot
*>(phys
);
192 spawnBot
->updateProfile(10);
199 if(!phys
->isRooted())
201 CSpawnBot
* spawnBot
= dynamic_cast<CSpawnBot
*>(phys
);
204 spawnBot
->updateProfile(10);