1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "egs_interface.h"
23 #include "server_share/msg_ai_service.h"
24 #include "ai_bot_fauna.h"
25 #include "ai_grp_fauna.h"
26 #include "ai_bot_npc.h"
27 #include "ai_grp_npc.h"
28 #include "nel/misc/path.h"
30 extern bool simulateBug(int bugId
);
32 using namespace NLMISC
;
33 using namespace NLNET
;
37 // call back for synchronize time and day
38 static void cbKamiImpact( NLNET::CMessage
& msgin
, const std::string
&serviceName
, NLNET::TServiceId serviceId
)
40 NLMISC::CEntityId charId
;
44 // Send message to AIS for kami impact
45 msgin
.serial( charId
);
46 msgin
.serial( depositId
);
47 msgin
.serial( score
);
50 // classic init(), update() and release()
51 void CEGSInterface::init()
53 NLNET::TUnifiedCallbackItem _cbArray
[] =
55 { "KAMI_IMPACT", cbKamiImpact
},
57 CUnifiedNetwork::getInstance()->addCallbackArray( _cbArray
, sizeof(_cbArray
) / sizeof(_cbArray
[0]) );
60 void CEGSInterface::update()
63 // flush output messages
66 void CEGSInterface::release()
70 void CUserEventMsgImp::callback (const std::string
&name
, NLNET::TServiceId id
)
72 CAIInstance
*aii
= CAIS::instance().getAIInstance(InstanceNumber
);
75 CGroup
*grp
= aii
->findGroup(GrpAlias
);
78 // ok, we found the correct group!
79 grp
->setEventParams(Params
);
80 grp
->setEvent(EventId
);
81 grp
->setEventParams(vector
<string
>());
87 nlwarning("CUserEventMsgImp event %u for group alias %u : no such group in instance %u !", EventId
, GrpAlias
, InstanceNumber
);
91 void CSetEscortTeamIdImp::callback (const std::string
&name
, NLNET::TServiceId id
)
93 // for each alias, retrieve the group and sets the escort team
94 for (uint i
=0; i
<Groups
.size(); ++i
)
96 CAIInstance
*aii
= CAIS::instance().getAIInstance(InstanceNumber
);
99 CGroup
*grp
= aii
->findGroup(Groups
[i
]); // Fake, to remove when EGS can tell us the corresponding world number.
102 grp
->setEscortTeamId(TeamId
);
105 nlwarning("CSetEscortTeamIdImp : can't find group with alias %u", Groups
[i
]);
109 nlwarning("CSetEscortTeamIdImp::callback : can't find AIInstance %u", InstanceNumber
);
116 //////////////////////////////////////////////////////////////////////////
117 // Loot Finished or no loot, EGS ask to remove the creature.
119 void CCreatureDespawnImp::callback (const std::string
&name
, NLNET::TServiceId id
)
121 for (uint i
= 0; i
< Entities
.size(); i
++)
123 CAIEntityPhysical
*const ep
= CAIS::instance().getEntityPhysical(Entities
[i
]);
125 continue; // not spawn
127 switch(ep
->getRyzomType())
130 // ok, warn the grp that this bot is totally looted, so we can despawn it
132 CSpawnBotNpc
*botNpc
= static_cast<CSpawnBotNpc
*>(ep
);
133 botNpc
->spawnGrp().addBotToDespawnAndRespawnTime(&botNpc
->getPersistent(), 1, botNpc
->spawnGrp().getPersistent().respawnTime());
136 case RYZOMID::creature
: // Fauna.
138 CSpawnBotFauna
*botFauna
= static_cast<CSpawnBotFauna
*>(ep
);
142 botFauna
->spawnGrp().addBotToDespawnAndRespawnTime(&botFauna
->getPersistent(),1,2); // 1 second.
146 // set time before respawn
147 sint32 RespawnTime
= botFauna
->spawnGrp().getPersistent().timer(CGrpFauna::RESPAWN_TIME
);
148 botFauna
->spawnGrp().addBotToDespawnAndRespawnTime(&botFauna
->getPersistent(), 1, RespawnTime
); // 1 tick before despawn
152 case RYZOMID::pack_animal
: // Pet.
154 CSpawnBotPet
*spawnBotPet
= static_cast<CSpawnBotPet
*>(ep
);
155 spawnBotPet
->getPersistent().despawnBot(); // direct despawn.
160 nlwarning("CCreatureDespawnImp Entity %d is not processed", Entities
[i
].getIndex());
166 //////////////////////////////////////////////////////////////////////////
168 void CAddHandledAIGroupImp::callback (const std::string
&name
, NLNET::TServiceId id
)
170 CCont
<CAIInstance
> &instances
= CAIS::instance().AIList();
172 for (uint i
=0; i
<instances
.size(); ++i
)
174 CAIInstance
*aii
= instances
[i
];
178 CGroupNpc
*grp
= dynamic_cast<CGroupNpc
*>(aii
->findGroup(GroupAlias
));
181 nlinfo("CAddHandledAIGroupImp on group %u user:%s miss:%d", GroupAlias
, PlayerRowId
.toString().c_str(), MissionAlias
);
182 // ok, we found the correct group!
183 grp
->addHandle(PlayerRowId
, MissionAlias
, DespawnTimeInTick
);
188 // debug only : AIS can receive message for not the same AiInstance as the group
189 //nlwarning("CAddHandledAIGroupImp group alias %u : not found !", GroupAlias);
192 //////////////////////////////////////////////////////////////////////////
194 void CDelHandledAIGroupImp::callback (const std::string
&name
, NLNET::TServiceId id
)
196 CCont
<CAIInstance
> &instances
= CAIS::instance().AIList();
198 for (uint i
=0; i
<instances
.size(); ++i
)
200 CAIInstance
*aii
= instances
[i
];
204 CGroupNpc
*grp
= dynamic_cast<CGroupNpc
*>(aii
->findGroup(GroupAlias
));
207 nlinfo("CDelHandledAIGroupImp on group %u user:%s miss:%d", GroupAlias
, PlayerRowId
.toString().c_str(), MissionAlias
);
208 // ok, we found the correct group!
209 grp
->delHandle(PlayerRowId
, MissionAlias
);
213 // debug only : AIS can receive message for not the same AiInstance as the group
214 //nlwarning("CDelHandledAIGroupImp group alias %u : no found !", GroupAlias);