forked from InfiniteRasa/Game-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamicObject.cpp
More file actions
677 lines (623 loc) · 23.1 KB
/
dynamicObject.cpp
File metadata and controls
677 lines (623 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
#include "global.h"
#define ACTION_USEOBJECT 80
extern sint32 gridL1;
extern sint32 gridL2;
extern sint32 gridCount;
extern sint32** entityPosGrid;
extern sint32** forcefieldMap;
extern dynObjectType_t dynObjectType_banedropship;
#include<math.h>
// Convert from Euler Angles
void _quaternion_fromEuler(float pitch, float yaw, float roll, float quatOut[4])
{
// Basically we create 3 Quaternions, one for pitch, one for yaw, one for roll
// and multiply those together.
// the calculation below does the same, just sint16er
float p = pitch * 1.57079f / 2.0f;
float y = yaw * 1.57079f / 2.0f;
float r = roll * 1.57079f / 2.0f;
float sinp = sin(p);
float siny = sin(y);
float sinr = sin(r);
float cosp = cos(p);
float cosy = cos(y);
float cosr = cos(r);
quatOut[0] = sinr * cosp * cosy - cosr * sinp * siny; // x
quatOut[1] = cosr * sinp * cosy + sinr * cosp * siny; // y
quatOut[2] = cosr * cosp * siny - sinr * sinp * cosy; // z
quatOut[3] = cosr * cosp * cosy + sinr * sinp * siny; // w
//normalise();
// Don't normalize if we don't have to
float mag2 = quatOut[3] * quatOut[3] + quatOut[0] * quatOut[0] + quatOut[1] * quatOut[1] + quatOut[2] * quatOut[2];
if (fabs(mag2 - 1.0f) > 0.00001f) {
float mag = sqrt(mag2);
quatOut[3] /= mag;
quatOut[0] /= mag;
quatOut[1] /= mag;
quatOut[2] /= mag;
}
}
dynObject_t *_dynamicObject_create(uint32 classId, dynObjectType_t* objectType)
{
if( objectType == NULL )
{
printf("Error: Cannot create object with no type\n", objectType);
return NULL;
}
dynObject_t *dynObject = (dynObject_t*)malloc(sizeof(dynObject_t));
dynObject->entityId = entityMgr_getFreeEntityIdForObject();
dynObject->type = objectType;
//if( objectType == OBJECTTYPE_FOOTLOCKER )
// __debugbreak(); // todo
//else if( objectType == OBJECTTYPE_BANE_DROPSHIP )
// dynObject->type = &dynObjectType_banedropship;
//else
//{
// dynObject->type = &dynObjectType_defaultObject;
// printf("Error: No dynamic object type found for typeID %d\n", objectType);
//}
//
//dynObject->objectType = objectType;
dynObject->objectData = NULL;
dynObject->entityClassId = classId;
dynObject->x = 0.0f;
dynObject->y = 0.0f;
dynObject->z = 0.0f;
dynObject->rotX = 0.0f;
dynObject->rotY = 0.0f;
dynObject->rotZ = 0.0f;
entityMgr_registerEntity(dynObject->entityId, dynObject);
return dynObject;
}
/* Destroys an object on client and serverside
* Frees the memory and informs clients about removal
*/
void dynamicObject_destroy(mapChannel_t *mapChannel, dynObject_t *dynObject)
{
// TODO, check timers
// remove from world
entityMgr_unregisterEntity(dynObject->entityId);
cellMgr_removeFromWorld(mapChannel, dynObject);
// destroy callback
if( dynObject->type->destroy )
dynObject->type->destroy(mapChannel, dynObject);
// free memory
if( dynObject->objectData )
free(dynObject->objectData);
free(dynObject);
}
void dynamicObject_setPosition(dynObject_t *dynamicObject, float x, float y, float z)
{
dynamicObject->x = x;
dynamicObject->y = y;
dynamicObject->z = z;
}
void dynamicObject_setRotation(dynObject_t *dynamicObject, float pitch, float yaw, float roll)
{
dynamicObject->rotX = pitch;
dynamicObject->rotY = yaw;
dynamicObject->rotZ = roll;
}
void dynamicObject_setPeriodicUpdate(mapChannel_t *mapChannel, dynObject_t *dynamicObject, uint8 timerID, sint32 periodInMS)
{
// create work entry
dynObject_workEntry_t *workEntry = (dynObject_workEntry_t*)malloc(sizeof(dynObject_workEntry_t));
workEntry->object = dynamicObject;
workEntry->period = periodInMS;
workEntry->timeLeft = periodInMS;
workEntry->entityId = dynamicObject->entityId;
workEntry->timerID = timerID;
// register
mapChannel->updateObjectList.push_back(workEntry);
}
void dynamicObject_stopPeriodicUpdate(mapChannel_t *mapChannel, dynObject_t *dynamicObject, uint8 timerID)
{
// use iterator to find entry and delete it
if( mapChannel->updateObjectList.empty() )
return;
std::vector<dynObject_workEntry_t*>::iterator itr = mapChannel->updateObjectList.begin();
while (itr != mapChannel->updateObjectList.end())
{
dynObject_workEntry_t *workEntry = *itr;
if( workEntry->object == dynamicObject && workEntry->timerID == timerID )
{
mapChannel->updateObjectList.erase(itr);
free(workEntry);
break;
}
itr++;
}
}
//dynObject_t *dynamicObject_createFootlocker(float x, float y, float z, float rotX, float rotY, float rotZ)
//{
// return NULL;
// //dynObject_t *dynObject = _dynamicObject_create(21030, OBJECTTYPE_FOOTLOCKER);
// //if( !dynObject )
// // return NULL;
// //dynamicObject_setPosition(dynObject, x, y, z);
// //// set footlocker data
// //// todo
// //return dynObject;
//}
//
//dynObject_t *dynamicObject_createCustom(sint32 classId, float x, float y, float z, float rotX, float rotY, float rotZ)
//{
// return NULL;
// //dynObject_t *dynObject = _dynamicObject_create(classId, OBJECTTYPE_UNDEFINED);
// //if( !dynObject )
// // return NULL;
// //dynamicObject_setPosition(dynObject, x, y, z);
// //return dynObject;
//}
void dynamicObject_createObjectOnClient(mapChannelClient_t *client, dynObject_t *dynObject)
{
if( !dynObject )
return;
pyMarshalString_t pms;
// create object entity
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addInt(&pms, dynObject->entityId); // entityID
pym_addInt(&pms, dynObject->entityClassId); // classID
pym_addNoneStruct(&pms); // entityData (dunno)
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(client->cgm, 5, METHODID_CREATEPYHSICALENTITY, pym_getData(&pms), pym_getLen(&pms));
// set position
pym_init(&pms);
pym_tuple_begin(&pms);
// position
pym_tuple_begin(&pms);
pym_addFloat(&pms, dynObject->x); // x
pym_addFloat(&pms, dynObject->y); // y
pym_addFloat(&pms, dynObject->z); // z
pym_tuple_end(&pms);
// rotation quaterninion
float qOut[4];
_quaternion_fromEuler(dynObject->rotX, dynObject->rotY, dynObject->rotZ, qOut);
pym_tuple_begin(&pms);
pym_addFloat(&pms, qOut[0]);
pym_addFloat(&pms, qOut[1]);
pym_addFloat(&pms, qOut[2]);
pym_addFloat(&pms, qOut[3]);
pym_tuple_end(&pms);
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(client->cgm, dynObject->entityId, 243, pym_getData(&pms), pym_getLen(&pms));
// additional info depending on type
// if (dynObject->objectType == OBJECTTYPE_AFS_TURRET)
// {
//
//
//
// pym_init(&pms);
// pym_tuple_begin(&pms); // Packet Start
// pym_addInt(&pms, 242); // Action ID //
// pym_addInt(&pms, 1); // Arg ID //
// pym_list_begin(&pms); // Hits Start
// pym_addLong(&pms, dynObject->entityId); // Each hit creature
// pym_list_end(&pms); // Hits End
// pym_list_begin(&pms); // Misses Start
// pym_list_end(&pms); // Misses End
// pym_list_begin(&pms); // Misses Data Start
// pym_list_end(&pms); // Misses Data End
// pym_list_begin(&pms); // Hits Data Start
// pym_tuple_begin(&pms); // Each Hit tuple start
// pym_addInt(&pms, dynObject->entityId); // Creature entity ID
// pym_tuple_begin(&pms); // rawInfo start
// pym_addInt(&pms, 1); //self.damageType = normal
// pym_addInt(&pms, 0); //self.reflected = 0
// pym_addInt(&pms, 0); //self.filtered = 0
// pym_addInt(&pms, 0); //self.absorbed = 0
// pym_addInt(&pms, 0); //self.resisted = 0
// pym_addInt(&pms, 1); //self.finalAmt = missile->damageA
// pym_addInt(&pms, 0); //self.isCrit = 0
// pym_addInt(&pms, 0); //self.deathBlow = 0
// pym_addInt(&pms, 0); //self.coverModifier = 0
// pym_addInt(&pms, 0); //self.wasImmune = 0
// //targetEffectIds // 131
// pym_list_begin(&pms);
// pym_list_end(&pms);
// //sourceEffectIds
// pym_list_begin(&pms);
// pym_list_end(&pms);
// pym_tuple_end(&pms); // rawInfo end
// //pym_addNoneStruct(&pms); // OnHitData
// //pym_addInt(&pms, 12);
//
// pym_tuple_end(&pms); // Each Hit tuple start
// pym_list_end(&pms); // Hits Data End
// pym_tuple_end(&pms); // Packet End
// // 311
// netMgr_cellDomain_pythonAddMethodCallRaw(client->mapChannel, dynObject, dynObject->entityId, 125, pym_getData(&pms), pym_getLen(&pms));
//
// }
// if (dynObject->objectType == OBJECTTYPE_TORIODCANNON)
// {
// pyMarshalString_t pms;
// pym_init(&pms);
// pym_tuple_begin(&pms);
// pym_addInt(&pms, 56);
// pym_addInt(&pms, 0);
// pym_tuple_end(&pms);
// netMgr_pythonAddMethodCallRaw(client->cgm, dynObject->entityId, METHODID_FORCESTATE, pym_getData(&pms), pym_getLen(&pms));
// }
// if (dynObject->objectType == OBJECTTYPE_BASEWORMHOLE)
// {
// pyMarshalString_t pms;
// pym_init(&pms);
// pym_tuple_begin(&pms);
// pym_addInt(&pms, 56);
// pym_addInt(&pms, 0);
// pym_tuple_end(&pms);
// netMgr_pythonAddMethodCallRaw(client->cgm, dynObject->entityId, METHODID_FORCESTATE, pym_getData(&pms), pym_getLen(&pms));
// }
// if (dynObject->objectType == OBJECTTYPE_TELEPORTER)
// {
// pym_init(&pms);
// pym_tuple_begin(&pms);
// pym_addInt(&pms, 1); // enabled
// pym_addInt(&pms, 80); // curState
// pym_addNoneStruct(&pms); // nameOverrideId
// pym_addInt(&pms, 1000); // windupTime
// pym_addInt(&pms, 0); // missionActivated
// pym_tuple_end(&pms);
// netMgr_pythonAddMethodCallRaw(client->cgm, dynObject->entityId, 229, pym_getData(&pms), pym_getLen(&pms));
// }
// if (dynObject->objectType == OBJECTTYPE_DOOR)
// {
//
// pyMarshalString_t pms;
// pym_init(&pms);
// pym_tuple_begin(&pms);
// pym_addInt(&pms, 91);
// pym_addInt(&pms, 25000);
// pym_tuple_end(&pms);
// netMgr_pythonAddMethodCallRaw(client->cgm, dynObject->entityId, 454, pym_getData(&pms), pym_getLen(&pms));
// }
// if (dynObject->objectType == OBJECTTYPE_FORCEFIELD)
// {
// pyMarshalString_t pms;
// pym_init(&pms);
// pym_tuple_begin(&pms);
// pym_addInt(&pms, 191);
// pym_addInt(&pms, 10000);
// pym_tuple_end(&pms);
// netMgr_pythonAddMethodCallRaw(client->mapChannel, dynObject->entityId, 454, pym_getData(&pms), pym_getLen(&pms));
//
// pym_init(&pms);
// pym_tuple_begin(&pms);
// pym_addInt(&pms, client->player->actor->entityId);
// pym_addInt(&pms, 0);
// pym_tuple_end(&pms);
// netMgr_pythonAddMethodCallRaw(client->mapChannel, dynObject->entityId, 624, pym_getData(&pms), pym_getLen(&pms));
//
// }
// if (dynObject->objectType == OBJECTTYPE_LOGOS)
// {
// pym_init(&pms);
// pym_tuple_begin(&pms);
// pym_addInt(&pms, 1); // enabled
// pym_addInt(&pms, 81); // curState
// pym_addNoneStruct(&pms); // nameOverrideId
// pym_addInt(&pms, 10000); // windupTime
// pym_addInt(&pms, 0); // missionActivated
// pym_tuple_end(&pms);
// netMgr_pythonAddMethodCallRaw(client->cgm, dynObject->entityId, 229, pym_getData(&pms), pym_getLen(&pms));
// }
}
// return false if the object timer entry should be removed
bool dynamicObject_process(mapChannel_t *mapChannel, dynObject_t *dynObject, uint8 timerID, sint32 timePassed)
{
return dynObject->type->periodicCallback(mapChannel, dynObject, timerID, timePassed);
}
void dynamicObject_check(mapChannel_t *mapChannel, sint32 timePassed)
{
// parse through all objects
std::vector<dynObject_workEntry_t*>::iterator dynObjectWorkEntryItr = mapChannel->updateObjectList.begin();
while( dynObjectWorkEntryItr != mapChannel->updateObjectList.end() )
{
dynObject_workEntry_t *dynObjectWorkEntry = *dynObjectWorkEntryItr;
dynObjectWorkEntry->timeLeft -= timePassed;
if( dynObjectWorkEntry->timeLeft <= 0 )
{
sint32 objTimePassed = dynObjectWorkEntry->period - dynObjectWorkEntry->timeLeft;
dynObjectWorkEntry->timeLeft += dynObjectWorkEntry->period;
// trigger object
bool remove = dynamicObject_process(mapChannel, dynObjectWorkEntry->object, dynObjectWorkEntry->timerID, objTimePassed);
if( remove == false )
{
dynObjectWorkEntryItr = mapChannel->updateObjectList.erase(dynObjectWorkEntryItr);
continue;
}
}
dynObjectWorkEntryItr++;
}
}
//---init all dynamic objects in mapchannel
void dynamicObject_init(mapChannel_t *mapChannel)
{
//dynObject_t *footLocker = dynamicObject_createFootlocker(-231.800781f, 101.050781f, -69.894531f, 0.0f, 0.0f, 0.0f);
//cellMgr_addToWorld(mapChannel, footLocker);
//dynamicObject_createHumanDropship(mapChannel, -231.800781f, 105.0f, -69.894531f);
}
//
//void dynamicObject_developer_createFootlocker(mapChannel_t *mapChannel, float x, float y, float z)
//{
// dynObject_t *footLocker = dynamicObject_createFootlocker(x, y, z, 0.0f, 0.0f, 0.0f);
// cellMgr_addToWorld(mapChannel, footLocker);
//}
//
//
//void dynamicObject_developer_createCustom(mapChannel_t *mapChannel, sint32 classId, float x, float y, float z)
//{
// dynObject_t *customObj = dynamicObject_createCustom(classId, x, y, z, 0.0f, 0.0f, 0.0f);
// cellMgr_addToWorld(mapChannel, customObj);
//}
void dynamicObject_teleporter_useObject(mapChannelClient_t *client, sint32 actionId, sint32 actionArgId, dynObject_t *teleporter)
{
if( actionId == ACTION_USEOBJECT )
{
typedef struct tloc
{
sint32 x;
sint32 y;
sint32 z;
float rotation; //not necessary, could add
sint32 mapContextId;
};
tloc telepos = {0};
client->player->actor->posX = 200.1f;
client->player->actor->posY = 200.1f;
client->player->actor->posZ = 200.1f;
cellMgr_addToWorld(client); // will introduce the player to all clients, including the current owner
// todo: send inventory
//printf("TODO: teleporter");
}
}
void dynamicObject_footlocker_useObject(mapChannelClient_t *client, sint32 actionId, sint32 actionArgId, dynObject_t *footlocker)
{
if( actionId == ACTION_USEOBJECT )
{
// use lockbox (230)
pyMarshalString_t pms;
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addInt(&pms, client->player->actor->entityId); // actorId
pym_addInt(&pms, 1); // curState
pym_addInt(&pms, 500); // windupTimeMs
pym_addNoneStruct(&pms); // args
pym_addNoneStruct(&pms); // entityData (dunno)
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(client->cgm, footlocker->entityId, 230, pym_getData(&pms), pym_getLen(&pms));
// todo: send inventory
printf("TODO: footlocker Should send inventory");
}
}
void dynamicObject_recv_RequestUseObject(mapChannelClient_t *client, uint8 *pyString, sint32 pyStringLen)
{
printf("Request use object\n");
// actionId
// actionArgId
// entityId
pyUnmarshalString_t pums;
pym_init(&pums, pyString, pyStringLen);
if( !pym_unpackTuple_begin(&pums) )
return;
sint32 actionId = pym_unpackInt(&pums);
sint32 actionArgId = pym_unpackInt(&pums);
unsigned long long entityId = pym_unpackLongLong(&pums);
if( entityMgr_getEntityType(entityId) != ENTITYTYPE_OBJECT )
return;
dynObject_t *dynObject = (dynObject_t*)entityMgr_get(entityId);
if( dynObject == NULL )
return;
// todo: Check if action already in progress and if yes, send error message
client->usedObject.actionId = actionId;
client->usedObject.actionArg = actionArgId;
client->usedObject.entityId = entityId;
if( dynObject->type->useObject )
dynObject->type->useObject(client->mapChannel, dynObject, client, actionId, actionArgId);
//pyMarshalString_t pms;
//switch( dynObject->objectType )
//{
//case OBJECTTYPE_TELEPORTER:
// printf("use teleporter\n");
// dynamicObject_teleporter_useObject(client, actionId, actionArgId, dynObject);
// break;
//
//case OBJECTTYPE_FOOTLOCKER:
// dynamicObject_footlocker_useObject(client, actionId, actionArgId, dynObject);
// break;
//case OBJECTTYPE_CONTROL_POINT:
// /*
// (176) (USE_CPOsint32_STATE_FACTION_A_OWNED)
// (177) (USE_CPOsint32_STATE_FACTION_B_CLAIMING)
// (179) (USE_CPOsint32_STATE_FACTION_B_OWNED)
// (180) (USE_CPOsint32_STATE_FACTION_A_CLAIMING)
// (181) (USE_CPOsint32_STATE_UNCLAIMED)
// */
// //printf("ActionID: %i - ActionArgID: %i\n", actionId, actionArgId);
// // send interruptible use
// pym_init(&pms);
// pym_tuple_begin(&pms);
// pym_addInt(&pms, client->player->actor->entityId); // actorID
// pym_tuple_end(&pms);
// netMgr_pythonAddMethodCallRaw(client->cgm, dynObject->entityId, 691, pym_getData(&pms), pym_getLen(&pms));
// client->player->actionEntityId = dynObject->entityId;
// // change CP state - ForceState
// pym_init(&pms);
// pym_tuple_begin(&pms);
// pym_addInt(&pms, 174); // 180
// pym_addInt(&pms, 10000);
// pym_tuple_end(&pms);
// netMgr_pythonAddMethodCallRaw(client->cgm, dynObject->entityId, 454, pym_getData(&pms), pym_getLen(&pms));
// client->mapChannel->cp_trigger.cb = _dynamicObject_controlpoint_callback;
// client->mapChannel->cp_trigger.param = client;
// client->mapChannel->cp_trigger.timeLeft = 9500;
// client->mapChannel->cp_trigger.period = 0;
// break;
//case OBJECTTYPE_LOGOS:
// printf("using logos\n");
// // Recv_Use(self, actorId, curStateId, windupTimeMs, *args):
// // send interruptible use
// pym_init(&pms);
// pym_tuple_begin(&pms);
// pym_addInt(&pms, client->player->actor->entityId); // actorID
// pym_addInt(&pms, 81);
// pym_addInt(&pms, 10000);
// pym_tuple_end(&pms);
// netMgr_pythonAddMethodCallRaw(client->cgm, dynObject->entityId, 230, pym_getData(&pms), pym_getLen(&pms));
// client->player->actionEntityId = dynObject->entityId;
// break;
//}
}
//bool _dynamicObject_controlpoint_callback(mapChannel_t *mapChannel, void *param, sint32 timePassed)
//{
// printf("callback control point activated!\n");
// mapChannelClient_t* client = (mapChannelClient_t*)param;
// if (client->player->actionEntityId == NULL)
// return true;
// printf("action entity is not null\n");
// // change CP state - ForceState
// pyMarshalString_t pms;
// pym_init(&pms);
// pym_tuple_begin(&pms);
// pym_addInt(&pms, 176); // 180
// pym_addInt(&pms, 10000);
// pym_tuple_end(&pms);
// netMgr_pythonAddMethodCallRaw(client->cgm, client->player->actionEntityId, 454, pym_getData(&pms), pym_getLen(&pms));
// // set usable
// pym_init(&pms);
// pym_tuple_begin(&pms);
// pym_addBool(&pms, false);
// pym_tuple_end(&pms);
// netMgr_pythonAddMethodCallRaw(client->cgm, client->player->actionEntityId, 203, pym_getData(&pms), pym_getLen(&pms));
// client->player->actionEntityId = NULL;
// // complete action (perform recovery)
// pym_init(&pms);
// pym_tuple_begin(&pms); // Packet Start
// pym_addInt(&pms, 80); // Action ID
// pym_addInt(&pms, 7); // Arg ID
// pym_tuple_end(&pms); // Packet End
// netMgr_pythonAddMethodCallRaw(client->cgm, client->player->actor->entityId, METHODID_PERFORMRECOVERY, pym_getData(&pms), pym_getLen(&pms));
// return true;
//}
void dynamicObject_recv_RequestActionInterrupt(mapChannelClient_t *client, uint8 *pyString, sint32 pyStringLen)
{
printf("Request action interrupt\n");
pyUnmarshalString_t pums;
pym_init(&pums, pyString, pyStringLen);
if( !pym_unpackTuple_begin(&pums) )
return;
sint32 actionId = pym_unpackInt(&pums);
sint32 actionArgId = pym_unpackInt(&pums);
if( client->usedObject.actionId != actionId || client->usedObject.actionArg != actionArgId || entityMgr_getEntityType(client->usedObject.entityId) != ENTITYTYPE_OBJECT )
{
// not the same action as the one the player currently executes
printf("RequestActionInterrupt: Wrong action or object disappeared\n");
return;
}
dynObject_t* dynObject = (dynObject_t*)entityMgr_get(client->usedObject.entityId);
if( dynObject )
{
if( dynObject->type->interruptUse )
dynObject->type->interruptUse(client->mapChannel, dynObject, client, actionId, actionArgId);
}
// complete action
pyMarshalString_t pms;
pym_init(&pms);
pym_tuple_begin(&pms); // Packet Start
pym_addInt(&pms, actionId); // Action ID // 1 Weapon attack
pym_addInt(&pms, actionArgId); // Arg ID // 133 pistol physical not crouched
pym_tuple_end(&pms); // Packet End
netMgr_pythonAddMethodCallRaw(client->cgm, client->player->actor->entityId, METHODID_PERFORMRECOVERY, pym_getData(&pms), pym_getLen(&pms));
// reset object use
client->usedObject.actionId = 0;
client->usedObject.actionArg = 0;
client->usedObject.entityId = 0;
}
// 1:n
void dynamicObject_cellIntroduceObjectToClients(mapChannel_t *mapChannel, dynObject_t *dynObj, mapChannelClient_t **playerList, sint32 playerCount)
{
for(sint32 i=0; i<playerCount; i++)
{
dynamicObject_createObjectOnClient(playerList[i], dynObj);
if( dynObj->type->appearForPlayers )
dynObj->type->appearForPlayers(mapChannel, dynObj, playerList, playerCount);
}
}
// n:1
void dynamicObject_cellIntroduceObjectsToClient(mapChannel_t *mapChannel, mapChannelClient_t *client, dynObject_t **objectList, sint32 objectCount)
{
mapChannelClient_t* tempPlayerList[1];
tempPlayerList[0] = client;
for(sint32 i=0; i<objectCount; i++)
{
dynamicObject_createObjectOnClient(client, objectList[i]);
if( objectList[i]->type->appearForPlayers )
objectList[i]->type->appearForPlayers(mapChannel, objectList[i], tempPlayerList, 1);
}
}
void dynamicObject_cellDiscardObjectToClients(mapChannel_t *mapChannel, dynObject_t *dynObj, mapChannelClient_t **playerList, sint32 playerCount)
{
if( !dynObj )
return;
if( dynObj->type->disappearForPlayers )
dynObj->type->disappearForPlayers(mapChannel, dynObj, playerList, playerCount);
// send entity destroy
pyMarshalString_t pms;
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addInt(&pms, dynObj->entityId); // entityID
pym_tuple_end(&pms);
for(sint32 i=0; i<playerCount; i++)
netMgr_pythonAddMethodCallRaw(playerList[i]->cgm, 5, 56, pym_getData(&pms), pym_getLen(&pms));
}
void dynamicObject_cellDiscardObjectsToClient(mapChannel_t *mapChannel, mapChannelClient_t *client, dynObject_t **objectList, sint32 objectCount)
{
if( !client )
return;
pyMarshalString_t pms;
mapChannelClient_t* tempPlayerList[1];
tempPlayerList[0] = client;
for(sint32 i=0; i<objectCount; i++)
{
if( objectList[i]->type->disappearForPlayers )
objectList[i]->type->disappearForPlayers(mapChannel, objectList[i], tempPlayerList, 1);
// send entity destroy
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addInt(&pms, objectList[i]->entityId); // entityID
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(client->cgm, 5, 56, pym_getData(&pms), pym_getLen(&pms));
}
}
// TEEEEEEST
void dynamicObject_createLogosObject(mapChannel_t *mapChannel, float x, float y, float z)
{
//dynObject_t *dynObject = _dynamicObject_create(7302, OBJECTTYPE_LOGOS); // 3814
//if( !dynObject )
// return;
//dynamicObject_setPosition(dynObject, x, y, z);
//cellMgr_addToWorld(mapChannel, dynObject);
}
void dynamicObject_createHumanDropship(mapChannel_t *mapChannel, float x, float y, float z)
{
//dynObject_t *dynObject = _dynamicObject_create(9269, OBJECTTYPE_BANE_DROPSHIP); // 3814
//if( !dynObject )
// return;
//printf("Human Dropship Entity ID: %u\n", dynObject->entityId);
//dynamicObject_setPosition(dynObject, x, y, z);
////dynamicObject_setRotation(dynObject, 0.0f, 0.0f, 0.0f);
//dynObject->stateId = 1;
//cellMgr_addToWorld(mapChannel, dynObject);
}
void dynamicObject_forceState(clientGamemain_t* cgm, uint32 entityId, sint32 state)
{
pyMarshalString_t pms;
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addInt(&pms, state);
pym_addInt(&pms, 10000);
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(cgm, entityId, 454, pym_getData(&pms), pym_getLen(&pms));
}