Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / combat_interface.cpp
blob94d874bd843bf98ca68a596b938cba71d6bc4c93
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
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/>.
20 #include "stdpch.h"
21 // Game share
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"
27 #include "ai.h"
28 #include "ai_entity_physical.h"
29 #include "ai_entity_physical_inline.h"
30 #include "ai_instance.h"
31 #include "ai_mgr.h"
32 #include "ai_profile_npc.h"
34 using namespace NLMISC;
35 using namespace NLNET;
36 using namespace std;
37 using namespace EFFECT_FAMILIES;
39 // GLOBALS
40 std::list <CCombatInterface::CEvent> CCombatInterface::_events;
42 static bool verboseLog=false;
45 // MACROS
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);
65 CSheetId::init();
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 )
87 && AggroAdd[i]==0 )
88 continue;
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","")
103 if(args.size()>1)
104 return false;
106 if(args.size()==1)
107 StrToBool (verboseLog, args[0]);
109 log.displayNL("verboseCombatLogging is %s",verboseLog?"ON":"OFF");
110 return true;
113 //-----------------------------------------------
114 // cbChangeMode :
115 //-----------------------------------------------
117 //void cbChangeMode( CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
119 // TDataSetRow row;
120 // msgin.serial( row );
122 // // read the new Mode
123 // MBEHAV::TMode mode;
124 // msgin.serial( mode );
126 // CAIEntityPhysical *phys=CAIS::getEntityPhysical(row);
128 // if ( phys
129 // && phys->getRyzomType()!=RYZOMID::player
130 // && phys->isAlive() )
131 // {
132 // static_cast<CModEntityPhysical*>(phys)->setModeStruct(mode);
133 // }
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]);
142 if (!phys)
143 continue;
145 switch ((TEffectFamily)Families[i])
147 case Stun:
148 case CombatStun:
149 case Mezz:
150 phys->stun()++;
151 break;
153 case Root:
154 phys->root()++;
155 break;
157 case Blind:
158 phys->blind()++;
159 break;
161 case Fear:
162 phys->fear()++;
163 break;
165 default:
166 break;
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]);
178 if (!phys)
179 continue;
181 switch ((TEffectFamily)Families[i])
183 case Stun:
184 case CombatStun:
185 case Mezz:
186 phys->stun()--;
187 if(!phys->isStuned())
189 CSpawnBot * spawnBot = dynamic_cast<CSpawnBot*>(phys);
190 if(spawnBot)
192 spawnBot->updateProfile(10);
195 break;
197 case Root:
198 phys->root()--;
199 if(!phys->isRooted())
201 CSpawnBot * spawnBot = dynamic_cast<CSpawnBot*>(phys);
202 if(spawnBot)
204 spawnBot->updateProfile(10);
207 break;
209 case Blind:
210 phys->blind()--;
211 break;
213 case Fear:
214 phys->fear()--;
215 break;
217 default:
218 break;