载入中...
搜索中...
未找到
Weapon.cpp
浏览该文件的文档.
1#include "weapon/Weapon.h"
2
3#include "common/Value.h"
8
9#include <squirrel.h>
10#include <simplesquirrel/simplesquirrel.hpp>
11
12#include <algorithm>
13#include <cmath>
14#include <memory>
15
16namespace eve::weapon {
17
19
20namespace {
21
22template <typename T>
23T* resolve(const ecs::EntityHandle& h) {
24 return static_cast<T*>(ecs::try_get(h));
25}
26
27template <typename T>
28void destroyHandles(std::vector<ecs::EntityHandle>& hs) {
29 for (auto& h : hs) {
30 if (ecs::Entity* e = ecs::try_get(h)) ecs::DestroyEntity(e);
31 }
32 hs.clear();
33}
34
35template <typename T>
36void registerCppEntityClassForScript(const ssq::Class& cls) {
37 eve::registerCppEntityView(cls, [](ssq::Array& out) {
38 HSQUIRRELVM vm = out.getHandle();
39 sq_pushobject(vm, out.getRaw());
40 ecs::Table* table = ecs::current();
41 if (table == nullptr) {
42 sq_pop(vm, 1);
43 return;
44 }
45 ecs::IComponentManager& cm = table->getOrCreateManager<T>();
46 auto* reg = cm.getOrCreateRegistryComponentBuffer<T>();
47 std::vector<ecs::IComponentBuffer*> stack;
48 stack.push_back(reg);
49 while (!stack.empty()) {
50 ecs::IComponentBuffer* buf = stack.back();
51 stack.pop_back();
52 auto* r = dynamic_cast<ecs::IRegistryComponentBuffer*>(buf);
53 if (r != nullptr) {
54 for (uint32_t i = 0; i < r->entity_count(); ++i) {
55 ecs::Entity* ent = r->entity_at(i);
56 if (ent != nullptr && ecs::is_entity_visible(ent)) {
57 ssq::detail::pushByPtr<T>(vm, static_cast<T*>(ent));
58 sq_arrayappend(vm, -2);
59 }
60 }
61 }
62 if (buf->children != nullptr) stack.push_back(buf->children);
63 if (buf->next != nullptr) stack.push_back(buf->next);
64 }
65 sq_pop(vm, 1);
66 });
67}
68
69} // namespace
70
71const char* fireModeName(FireMode mode) {
72 switch (mode) {
73 case FireMode::Single: return "single";
74 case FireMode::Burst: return "burst";
75 case FireMode::Auto: return "auto";
76 }
77 return "single";
78}
79
80FireMode fireModeFromName(const std::string& name) {
81 if (name == "burst") return FireMode::Burst;
82 if (name == "auto") return FireMode::Auto;
83 return FireMode::Single;
84}
85
87 switch (kind) {
88 case WeaponKind::Melee: return "melee";
89 case WeaponKind::Ranged: return "ranged";
90 case WeaponKind::Magic: return "magic";
91 case WeaponKind::Missile: return "missile";
92 case WeaponKind::Custom: return "custom";
93 }
94 return "ranged";
95}
96
97WeaponKind weaponKindFromName(const std::string& name) {
98 if (name == "melee") return WeaponKind::Melee;
99 if (name == "magic") return WeaponKind::Magic;
100 if (name == "missile") return WeaponKind::Missile;
101 if (name == "custom") return WeaponKind::Custom;
102 return WeaponKind::Ranged;
103}
104
105const char* attackStageName(AttackStage stage) {
106 switch (stage) {
107 case AttackStage::Idle: return "idle";
108 case AttackStage::Windup: return "windup";
109 case AttackStage::Active: return "active";
110 case AttackStage::Recover: return "recover";
111 }
112 return "idle";
113}
114
116 switch (type) {
117 case WeaponEventType::Fire: return "fire";
118 case WeaponEventType::ReloadStart: return "reload_start";
119 case WeaponEventType::ReloadEnd: return "reload_end";
120 case WeaponEventType::Empty: return "empty";
121 case WeaponEventType::WindupStart: return "windup_start";
122 case WeaponEventType::AttackEnd: return "attack_end";
123 case WeaponEventType::AimIn: return "aim_in";
124 case WeaponEventType::AimOut: return "aim_out";
125 }
126 return "unknown";
127}
128
130 WeaponEntity* w = WeaponEntity::create();
131 w->identity();
132 w->definition();
133 w->definitionBinding();
134 w->state();
135 w->aim();
136 return w;
137}
138
140 WeaponMountEntity* m = WeaponMountEntity::create();
141 m->identity();
142 m->limits();
143 m->state();
144 return m;
145}
146
148 WeaponRigEntity* r = WeaponRigEntity::create();
149 r->identity();
150 r->held();
151 r->state();
152 return r;
153}
154
156 AmmoPoolEntity* p = AmmoPoolEntity::create();
157 p->identity();
158 p->state();
159 return p;
160}
161
162// ---------------------------------------------------------------------------
163// 模块生命周期
164// ---------------------------------------------------------------------------
165
167 WeaponSystem::setEventSink([this](const WeaponEvent& e) { events_.push_back(e); });
169}
170
172 destroyHandles<WeaponEntity>(weapons_);
173 destroyHandles<WeaponMountEntity>(mounts_);
174 destroyHandles<WeaponRigEntity>(rigs_);
175 destroyHandles<AmmoPoolEntity>(pools_);
178}
179
180// ---------------------------------------------------------------------------
181// 武器模板
182// ---------------------------------------------------------------------------
183
184int Weapon::registerWeaponsFromJson(const std::string& json) {
185 auto canonical = eve::Value::fromJson(json);
186 if (!canonical) {
187 canonical.ignore("weapon definition input could not be parsed as canonical Value");
188 return 0;
189 }
190
191 int n = 0;
192 const auto publish = [this, &n](const eve::Value& value) {
193 const auto* object = value.getIf<eve::Value::Object>();
194 if (object == nullptr) return;
195 const auto id = object->find("id");
196 const auto* name = id == object->end() ? nullptr : id->second.getIf<std::string>();
197 if (name == nullptr || name->empty()) return;
198
199 auto encoded = value.toJson();
200 if (!encoded) {
201 encoded.ignore("weapon definition value could not be serialized canonically");
202 return;
203 }
205 source.type = "weapon";
206 source.id = *name;
207 source.version = eve::SchemaVersion(1);
208 source.json = encoded.value();
209 auto typed = parseWeaponDefinition(source);
210 if (!typed) {
211 typed.ignore("weapon definition failed typed projection validation");
212 return;
213 }
214
215 auto current = definitionRegistry_.resolve("weapon", *name);
216 const bool exists = current.ok();
217 if (!exists && current.status().code() != eve::StatusCode::NotFound) return;
218 auto stored = exists ? definitionRegistry_.replace("weapon", *name, 1, source.json)
219 : definitionRegistry_.insert("weapon", *name, 1, source.json);
220 if (stored) {
221 ++n;
222 } else {
223 stored.ignore("weapon definition registry rejected canonical registration");
224 }
225 };
226 const eve::Value& root = canonical.value();
227 if (const auto* array = root.getIf<eve::Value::Array>()) {
228 for (const auto& value : *array) publish(value);
229 } else {
230 publish(root);
231 }
232 return n;
233}
234
236 while (definitionRegistry_.countType("weapon") > 0) {
237 const auto* definition = definitionRegistry_.atType("weapon", 0);
238 if (definition == nullptr) break;
239 auto result = definitionRegistry_.remove("weapon", definition->id);
240 if (!result) result.ignore("weapon definition registry removal failed");
241 }
242}
243
244int Weapon::getWeaponDefinitionCount() { return definitionRegistry_.countType("weapon"); }
245
246bool Weapon::hasWeaponDefinition(const std::string& id) { return definitionRegistry_.resolve("weapon", id).ok(); }
247
248std::string Weapon::getWeaponDefinitionLogic(const std::string& id) {
249 auto definition = findDef(id);
250 if (!definition) {
251 definition.ignore("legacy scalar query returns empty for an unknown weapon definition");
252 return {};
253 }
254 return definition.value().logic;
255}
256
257float Weapon::getWeaponDefinitionDamage(const std::string& id) {
258 auto definition = findDef(id);
259 if (!definition) {
260 definition.ignore("legacy scalar query returns zero for an unknown weapon definition");
261 return 0.f;
262 }
263 return definition.value().damage;
264}
265
266float Weapon::getWeaponDefinitionRange(const std::string& id) {
267 auto definition = findDef(id);
268 if (!definition) {
269 definition.ignore("legacy scalar query returns zero for an unknown weapon definition");
270 return 0.f;
271 }
272 return definition.value().range;
273}
274
276
278
279eve::Result<WeaponDefinition> Weapon::findDef(const std::string& id) const {
280 auto resolved = definitionRegistry_.resolve("weapon", id);
282 return parseWeaponDefinition(resolved.value().get());
283}
284
285// ---------------------------------------------------------------------------
286// 工厂
287// ---------------------------------------------------------------------------
288
289WeaponEntity* Weapon::newWeapon(const std::string& defId) {
290 auto definition = findDef(defId);
291 if (!definition) {
292 definition.ignore("legacy nullable factory returns null for an unknown weapon definition");
293 return nullptr;
294 }
295 WeaponDefinition d = std::move(definition).takeValue();
296
298 w->identity()->id = defId + "#" + std::to_string(nextInstance_++);
299 w->identity()->defId = defId;
300 w->definition()->owned = std::make_shared<const WeaponDefinition>(std::move(d));
301 w->definition()->def = w->definition()->owned.get();
302 w->state()->stages = &w->definition()->def->stages;
303 const WeaponDefinition& storedDefinition = *w->definition()->def;
304 w->state()->selector = storedDefinition.fireMode;
305 w->state()->currentSpread = storedDefinition.spreadMin;
306
307 // 运行时资源:热武器 ammo 映射到弹匣/备用;其余形态从模板 resource 拷贝。
308 Resource& r = w->state()->resource;
309 r.kind = storedDefinition.resource.kind;
310 r.max = storedDefinition.resource.max;
311 r.regen = storedDefinition.resource.regen;
312 r.cost = storedDefinition.resource.cost;
313 r.infinite = storedDefinition.resource.infinite;
314 if (storedDefinition.kind == WeaponKind::Ranged) {
315 r.kind = ResourceKind::Ammo;
316 r.max = static_cast<float>(storedDefinition.magSize);
317 r.value = static_cast<float>(storedDefinition.magSize);
318 r.cost = 1.f;
319 r.reserve = storedDefinition.reserveSize < 0 ? 0 : storedDefinition.reserveSize;
320 r.infinite = storedDefinition.reserveSize < 0;
321 } else {
322 r.value = r.infinite ? 0.f : r.max;
323 }
324
325 weapons_.push_back(ecs::handle_of(w));
326 return w;
327}
328
329WeaponMountEntity* Weapon::newMount(const std::string& id, const std::string& type) {
331 m->identity()->id = id.empty() ? ("mount#" + std::to_string(nextInstance_++)) : id;
332 m->identity()->type = type;
333 mounts_.push_back(ecs::handle_of(m));
334 return m;
335}
336
337WeaponRigEntity* Weapon::newRig(const std::string& id, const std::string& wield) {
339 r->identity()->id = id.empty() ? ("rig#" + std::to_string(nextInstance_++)) : id;
340 r->identity()->wield = wield;
341 rigs_.push_back(ecs::handle_of(r));
342 return r;
343}
344
345// ---------------------------------------------------------------------------
346// 手持位操作
347// ---------------------------------------------------------------------------
348
350 if (rig == nullptr || w == nullptr) return false;
351 rig->state()->weapon = w;
352 return true;
353}
354
355WeaponEntity* Weapon::rigGetWeapon(WeaponRigEntity* rig) { return rig == nullptr ? nullptr : rig->state()->weapon; }
356
357void Weapon::rigSetPose(WeaponRigEntity* rig, float px, float py, float pz, float rx, float ry, float rz) {
358 if (rig == nullptr) return;
359 rig->held()->posX = px;
360 rig->held()->posY = py;
361 rig->held()->posZ = pz;
362 rig->held()->rotX = rx;
363 rig->held()->rotY = ry;
364 rig->held()->rotZ = rz;
365}
366
367// ---------------------------------------------------------------------------
368// 共享弹药池
369// ---------------------------------------------------------------------------
370
371AmmoPoolEntity* Weapon::newAmmoPool(const std::string& id, const std::string& ammoType, int max) {
373 p->identity()->id = id.empty() ? ("ammo#" + std::to_string(nextInstance_++)) : id;
374 p->identity()->ammoType = ammoType;
375 p->state()->max = max;
376 pools_.push_back(ecs::handle_of(p));
377 return p;
378}
379
381 if (pool == nullptr || n <= 0) return;
382 if (pool->state()->max < 0) {
383 pool->state()->count += n;
384 } else {
385 pool->state()->count = std::min(pool->state()->max, pool->state()->count + n);
386 }
387}
388
389int Weapon::ammoPoolGetCount(AmmoPoolEntity* pool) { return pool == nullptr ? 0 : pool->state()->count; }
390
392 if (w == nullptr || pool == nullptr) return false;
393 w->state()->ammoPool = pool;
394 return true;
395}
396
398 if (w != nullptr) w->state()->ammoPool = nullptr;
399}
400
401AmmoPoolEntity* Weapon::getAmmoPool(WeaponEntity* w) { return w == nullptr ? nullptr : w->state()->ammoPool; }
402
403// ---------------------------------------------------------------------------
404// 挂点操作
405// ---------------------------------------------------------------------------
406
408 if (m == nullptr || w == nullptr || m->state()->destroyed) return false;
409 m->state()->weapon = w;
410 return true;
411}
412
413WeaponEntity* Weapon::mountGetWeapon(WeaponMountEntity* m) { return m == nullptr ? nullptr : m->state()->weapon; }
414
415void Weapon::mountSetLimits(WeaponMountEntity* m, float yawMin, float yawMax, float pitchMin, float pitchMax,
416 float rotSpeed, float firingArc) {
417 if (m == nullptr) return;
418 m->limits()->yawMin = yawMin;
419 m->limits()->yawMax = yawMax;
420 m->limits()->pitchMin = pitchMin;
421 m->limits()->pitchMax = pitchMax;
422 m->limits()->rotSpeed = rotSpeed;
423 m->limits()->firingArc = firingArc;
424}
425
427 if (m == nullptr || m->state()->destroyed) return;
428 const float cyaw = std::clamp(yaw, m->limits()->yawMin, m->limits()->yawMax);
429 const float cpitch = std::clamp(pitch, m->limits()->pitchMin, m->limits()->pitchMax);
430
431 if (WeaponEntity* w = m->state()->weapon) {
432 w->aim()->desiredYaw = cyaw;
433 w->aim()->desiredPitch = cpitch;
434 w->aim()->turnSpeed = m->limits()->rotSpeed;
435 } else {
436 m->state()->yaw = cyaw;
437 m->state()->pitch = cpitch;
438 }
439}
440
442 if (m == nullptr) return;
443 m->state()->destroyed = true;
444}
445
446// ---------------------------------------------------------------------------
447// 武器操作
448// ---------------------------------------------------------------------------
449
450bool Weapon::fire(WeaponEntity* w, const FireRequest& req) { return w != nullptr && WeaponSystem::tryFire(*w, req); }
451
452bool Weapon::fireAt(WeaponEntity* w, float x, float y, float z, int shooterId) {
453 if (w == nullptr) return false;
454 AttackRequest req;
455 req.targetX = x;
456 req.targetY = y;
457 req.targetZ = z;
458 req.hasTarget = true;
459 req.shooterId = shooterId;
460 return WeaponSystem::tryFire(*w, req);
461}
462
463bool Weapon::attack(WeaponEntity* w, float yaw, float pitch, int shooterId) {
464 if (w == nullptr) return false;
465 AttackRequest req;
466 req.yaw = yaw;
467 req.pitch = pitch;
468 req.shooterId = shooterId;
469 if (const WeaponDefinition* d = w->definition()->def) {
470 req.arcAngle = d->arc;
471 req.aoeRadius = d->projectile.aoe;
472 }
473 return WeaponSystem::tryFire(*w, req);
474}
475
476bool Weapon::canFire(WeaponEntity* w) { return w != nullptr && WeaponSystem::canFire(*w); }
477
479 if (w != nullptr) WeaponSystem::startReload(*w);
480}
481
485
486void Weapon::setAim(WeaponEntity* w, float yaw, float pitch) {
487 if (w == nullptr) return;
488 w->aim()->desiredYaw = yaw;
489 w->aim()->desiredPitch = pitch;
490}
491
492bool Weapon::setFireMode(WeaponEntity* w, const std::string& mode) {
493 if (w == nullptr) return false;
494 const WeaponDefinition* d = w->definition()->def;
495 if (d == nullptr) return false;
496 const FireMode m = fireModeFromName(mode);
497 // 无可选模式 = 固定 fireMode,不允许切换。
498 if (d->selectableModes.empty()) return m == d->fireMode;
499 for (const FireMode sm : d->selectableModes)
500 if (sm == m) {
501 w->state()->selector = m;
502 return true;
503 }
504 return false;
505}
506
508 return w != nullptr ? fireModeName(w->state()->selector) : std::string{};
509}
510
512 const WeaponDefinition* d = w != nullptr ? w->definition()->def : nullptr;
513 return d != nullptr ? static_cast<int>(d->selectableModes.size()) : 0;
514}
515
517 const WeaponDefinition* d = w != nullptr ? w->definition()->def : nullptr;
518 if (d == nullptr || index < 0 || index >= static_cast<int>(d->selectableModes.size())) return std::string{};
519 return fireModeName(d->selectableModes[static_cast<size_t>(index)]);
520}
521
522bool Weapon::setAiming(WeaponEntity* w, bool aiming) {
523 if (w == nullptr || w->state()->aiming == aiming) return false;
524 w->state()->aiming = aiming;
525 WeaponEvent e;
527 e.weaponId = w->identity()->id;
528 if (const WeaponDefinition* d = w->definition()->def) e.defId = d->id;
530 return true;
531}
532
533bool Weapon::isAiming(WeaponEntity* w) { return w != nullptr && w->state()->aiming; }
534
536 const WeaponDefinition* d = w != nullptr ? w->definition()->def : nullptr;
537 return d != nullptr ? d->zoomFov : 0.f;
538}
539
540float Weapon::getSpread(WeaponEntity* w) { return w != nullptr ? w->state()->currentSpread : 0.f; }
541
542float Weapon::getRecoilPitch(WeaponEntity* w) { return w != nullptr ? w->state()->recoilPitch : 0.f; }
543
544float Weapon::getRecoilYaw(WeaponEntity* w) { return w != nullptr ? w->state()->recoilYaw : 0.f; }
545
546void Weapon::update(float dt) {
547 for (const ecs::EntityHandle& h : weapons_) {
548 if (WeaponEntity* w = resolve<WeaponEntity>(h)) WeaponSystem::update(*w, dt);
549 }
550 for (const ecs::EntityHandle& h : mounts_) {
551 WeaponMountEntity* m = resolve<WeaponMountEntity>(h);
552 if (m == nullptr || m->state()->destroyed) continue;
553 if (WeaponEntity* w = m->state()->weapon) {
554 m->state()->yaw = w->aim()->yaw;
555 m->state()->pitch = w->aim()->pitch;
556 }
557 }
558}
559
560// ---------------------------------------------------------------------------
561// 事件队列
562// ---------------------------------------------------------------------------
563
564void Weapon::clearEvents() { events_.clear(); }
565
566int Weapon::getEventCount() const { return static_cast<int>(events_.size()); }
567
568std::string Weapon::getEventType(int index) const {
569 return (index >= 0 && index < getEventCount()) ? weaponEventTypeName(events_[index].type) : std::string{};
570}
571
572std::string Weapon::getEventWeaponId(int index) const {
573 return (index >= 0 && index < getEventCount()) ? events_[index].weaponId : std::string{};
574}
575
576std::string Weapon::getEventDefId(int index) const {
577 return (index >= 0 && index < getEventCount()) ? events_[index].defId : std::string{};
578}
579
580std::string Weapon::getEventMountId(int index) const {
581 return (index >= 0 && index < getEventCount()) ? events_[index].mountId : std::string{};
582}
583
585 return (index >= 0 && index < getEventCount()) ? events_[index].ammoLeft : 0;
586}
587
588float Weapon::getEventArc(int index) const {
589 return (index >= 0 && index < getEventCount()) ? events_[index].arc : 0.f;
590}
591
592float Weapon::getEventAoe(int index) const {
593 return (index >= 0 && index < getEventCount()) ? events_[index].aoe : 0.f;
594}
595
597 return (index >= 0 && index < getEventCount()) ? events_[index].spread : 0.f;
598}
599
601 return (index >= 0 && index < getEventCount()) ? events_[index].pellets : 0;
602}
603
605 return (index >= 0 && index < getEventCount()) ? events_[index].recoilPitch : 0.f;
606}
607
609 return (index >= 0 && index < getEventCount()) ? events_[index].recoilYaw : 0.f;
610}
611
612std::string Weapon::getEventDamageType(int index) const {
613 return (index >= 0 && index < getEventCount()) ? events_[index].damageType : std::string{};
614}
615
616std::string Weapon::getEventElement(int index) const {
617 return (index >= 0 && index < getEventCount()) ? events_[index].element : std::string{};
618}
619
620std::string Weapon::getStage(WeaponEntity* w) const {
621 return w != nullptr ? attackStageName(w->state()->stage) : std::string{};
622}
623
624float Weapon::getResourceValue(WeaponEntity* w) const { return w != nullptr ? w->state()->resource.value : 0.f; }
625
626// ---------------------------------------------------------------------------
627// 脚本绑定
628// ---------------------------------------------------------------------------
629
630void Weapon::expose(ssq::Table& table) {
631 auto cls = table.addClass(name, Weapon::create, false);
632 expose(cls);
634
635 auto wCls = table.addClass<WeaponEntity>(
636 "WeaponEntity", std::function<WeaponEntity*()>([]() -> WeaponEntity* { return nullptr; }), false);
637 registerCppEntityClassForScript<WeaponEntity>(wCls);
638 wCls.addFunc("getId", [](WeaponEntity* w) -> std::string { return w ? w->identity()->id : std::string{}; });
639 wCls.addFunc("getDefId", [](WeaponEntity* w) -> std::string { return w ? w->identity()->defId : std::string{}; });
640 wCls.addFunc("getOwnerId", [](WeaponEntity* w) -> int { return w ? w->identity()->ownerId : 0; });
641 wCls.addFunc("setOwnerId", [](WeaponEntity* w, int v) {
642 if (w) w->identity()->ownerId = v;
643 });
644 wCls.addFunc("getMagAmmo", [](WeaponEntity* w) -> int {
645 return w ? static_cast<int>(w->state()->resource.value) : 0;
646 });
647 wCls.addFunc("getReserveAmmo", [](WeaponEntity* w) -> int { return w ? w->state()->resource.reserve : 0; });
648 wCls.addFunc("getResourceValue", [](WeaponEntity* w) -> float { return w ? w->state()->resource.value : 0.f; });
649 wCls.addFunc("getSpread", [](WeaponEntity* w) -> float { return w ? w->state()->currentSpread : 0.f; });
650 wCls.addFunc("getRecoilPitch", [](WeaponEntity* w) -> float { return w ? w->state()->recoilPitch : 0.f; });
651 wCls.addFunc("getRecoilYaw", [](WeaponEntity* w) -> float { return w ? w->state()->recoilYaw : 0.f; });
652 wCls.addFunc("getFireMode", [](WeaponEntity* w) -> std::string {
653 return w ? fireModeName(w->state()->selector) : std::string{};
654 });
655 wCls.addFunc("setFireMode", [](WeaponEntity* w, const std::string& mode) -> bool {
656 if (w == nullptr) return false;
657 const WeaponDefinition* d = w->definition()->def;
658 if (d == nullptr) return false;
659 const FireMode m = fireModeFromName(mode);
660 if (d->selectableModes.empty()) return m == d->fireMode;
661 for (const FireMode sm : d->selectableModes)
662 if (sm == m) {
663 w->state()->selector = m;
664 return true;
665 }
666 return false;
667 });
668 wCls.addFunc("isAiming", [](WeaponEntity* w) -> bool { return w != nullptr && w->state()->aiming; });
669 wCls.addFunc("setAiming", [](WeaponEntity* w, bool aiming) -> bool {
670 if (w == nullptr || w->state()->aiming == aiming) return false;
671 w->state()->aiming = aiming;
672 WeaponEvent e;
674 e.weaponId = w->identity()->id;
675 if (const WeaponDefinition* d = w->definition()->def) e.defId = d->id;
677 return true;
678 });
679 wCls.addFunc("getZoomFov", [](WeaponEntity* w) -> float {
680 const WeaponDefinition* d = w != nullptr ? w->definition()->def : nullptr;
681 return d != nullptr ? d->zoomFov : 0.f;
682 });
683 wCls.addFunc("getAmmoPool",
684 [](WeaponEntity* w) -> AmmoPoolEntity* { return w != nullptr ? w->state()->ammoPool : nullptr; });
685 wCls.addFunc("getStage", [](WeaponEntity* w) -> std::string {
686 return w ? attackStageName(w->state()->stage) : std::string{};
687 });
688 wCls.addFunc("isReloading", [](WeaponEntity* w) -> bool { return w != nullptr && w->state()->resource.reloading; });
689 wCls.addFunc("getCooldown", [](WeaponEntity* w) -> float { return w ? w->state()->cooldown : 0.f; });
690 wCls.addFunc("getYaw", [](WeaponEntity* w) -> float { return w ? w->aim()->yaw : 0.f; });
691 wCls.addFunc("getPitch", [](WeaponEntity* w) -> float { return w ? w->aim()->pitch : 0.f; });
692 wCls.addFunc("canFire", [](WeaponEntity* w) -> bool { return w != nullptr && WeaponSystem::canFire(*w); });
693 wCls.addFunc("fireAt", [](WeaponEntity* w, float x, float y, float z, int shooterId) -> bool {
694 if (w == nullptr) return false;
695 AttackRequest req;
696 req.targetX = x;
697 req.targetY = y;
698 req.targetZ = z;
699 req.hasTarget = true;
700 req.shooterId = shooterId;
701 return WeaponSystem::tryFire(*w, req);
702 });
703 wCls.addFunc("attack", [](WeaponEntity* w, float yaw, float pitch, int shooterId) -> bool {
704 if (w == nullptr) return false;
705 AttackRequest req;
706 req.yaw = yaw;
707 req.pitch = pitch;
708 req.shooterId = shooterId;
709 if (const WeaponDefinition* d = w->definition()->def) {
710 req.arcAngle = d->arc;
711 req.aoeRadius = d->projectile.aoe;
712 }
713 return WeaponSystem::tryFire(*w, req);
714 });
715 wCls.addFunc("startReload", [](WeaponEntity* w) {
717 });
718 wCls.addFunc("cancelReload", [](WeaponEntity* w) {
720 });
721 wCls.addFunc("setAim", [](WeaponEntity* w, float yaw, float pitch) {
722 if (w) {
723 w->aim()->desiredYaw = yaw;
724 w->aim()->desiredPitch = pitch;
725 }
726 });
727
728 auto mCls = table.addClass<WeaponMountEntity>(
729 "WeaponMountEntity", std::function<WeaponMountEntity*()>([]() -> WeaponMountEntity* { return nullptr; }),
730 false);
731 registerCppEntityClassForScript<WeaponMountEntity>(mCls);
732 mCls.addFunc("getId", [](WeaponMountEntity* m) -> std::string { return m ? m->identity()->id : std::string{}; });
733 mCls.addFunc("getType",
734 [](WeaponMountEntity* m) -> std::string { return m ? m->identity()->type : std::string{}; });
735 mCls.addFunc("getNodePath",
736 [](WeaponMountEntity* m) -> std::string { return m ? m->identity()->nodePath : std::string{}; });
737 mCls.addFunc("setNodePath", [](WeaponMountEntity* m, const std::string& v) {
738 if (m) m->identity()->nodePath = v;
739 });
740 mCls.addFunc("getWeapon", [](WeaponMountEntity* m) -> WeaponEntity* { return m ? m->state()->weapon : nullptr; });
741 mCls.addFunc("getYaw", [](WeaponMountEntity* m) -> float { return m ? m->state()->yaw : 0.f; });
742 mCls.addFunc("getPitch", [](WeaponMountEntity* m) -> float { return m ? m->state()->pitch : 0.f; });
743 mCls.addFunc("isDestroyed", [](WeaponMountEntity* m) -> bool { return m != nullptr && m->state()->destroyed; });
744 mCls.addFunc("destroy", [](WeaponMountEntity* m) {
745 if (m) m->state()->destroyed = true;
746 });
747 mCls.addFunc("aimAt", [](WeaponMountEntity* m, float yaw, float pitch) {
748 if (m == nullptr || m->state()->destroyed) return;
749 const float cyaw = std::clamp(yaw, m->limits()->yawMin, m->limits()->yawMax);
750 const float cpitch = std::clamp(pitch, m->limits()->pitchMin, m->limits()->pitchMax);
751 if (WeaponEntity* w = m->state()->weapon) {
752 w->aim()->desiredYaw = cyaw;
753 w->aim()->desiredPitch = cpitch;
754 w->aim()->turnSpeed = m->limits()->rotSpeed;
755 } else {
756 m->state()->yaw = cyaw;
757 m->state()->pitch = cpitch;
758 }
759 });
760
761 auto rCls = table.addClass<WeaponRigEntity>(
762 "WeaponRigEntity", std::function<WeaponRigEntity*()>([]() -> WeaponRigEntity* { return nullptr; }), false);
763 registerCppEntityClassForScript<WeaponRigEntity>(rCls);
764 rCls.addFunc("getId", [](WeaponRigEntity* r) -> std::string { return r ? r->identity()->id : std::string{}; });
765 rCls.addFunc("getWield",
766 [](WeaponRigEntity* r) -> std::string { return r ? r->identity()->wield : std::string{}; });
767 rCls.addFunc("getNodePath",
768 [](WeaponRigEntity* r) -> std::string { return r ? r->identity()->nodePath : std::string{}; });
769 rCls.addFunc("setNodePath", [](WeaponRigEntity* r, const std::string& v) {
770 if (r) r->identity()->nodePath = v;
771 });
772 rCls.addFunc("getWeapon", [](WeaponRigEntity* r) -> WeaponEntity* { return r ? r->state()->weapon : nullptr; });
773 rCls.addFunc("attachWeapon", [](WeaponRigEntity* r, WeaponEntity* w) -> bool {
774 if (r == nullptr || w == nullptr) return false;
775 r->state()->weapon = w;
776 return true;
777 });
778 rCls.addFunc("setPose", [](WeaponRigEntity* r, float px, float py, float pz, float rx, float ry, float rz) {
779 if (r == nullptr) return;
780 r->held()->posX = px;
781 r->held()->posY = py;
782 r->held()->posZ = pz;
783 r->held()->rotX = rx;
784 r->held()->rotY = ry;
785 r->held()->rotZ = rz;
786 });
787
788 auto pCls = table.addClass<AmmoPoolEntity>(
789 "AmmoPoolEntity", std::function<AmmoPoolEntity*()>([]() -> AmmoPoolEntity* { return nullptr; }), false);
790 registerCppEntityClassForScript<AmmoPoolEntity>(pCls);
791 pCls.addFunc("getId", [](AmmoPoolEntity* p) -> std::string { return p ? p->identity()->id : std::string{}; });
792 pCls.addFunc("getAmmoType",
793 [](AmmoPoolEntity* p) -> std::string { return p ? p->identity()->ammoType : std::string{}; });
794 pCls.addFunc("getCount", [](AmmoPoolEntity* p) -> int { return p ? p->state()->count : 0; });
795 pCls.addFunc("addAmmo", [](AmmoPoolEntity* p, int n) {
796 if (p == nullptr || n <= 0) return;
797 if (p->state()->max < 0) {
798 p->state()->count += n;
799 } else {
800 p->state()->count = std::min(p->state()->max, p->state()->count + n);
801 }
802 });
803 pCls.addFunc("setCount", [](AmmoPoolEntity* p, int n) {
804 if (p != nullptr) p->state()->count = n;
805 });
806}
807
808void Weapon::expose(ssq::Class& cls) {
809 cls.addFunc("registerWeaponsFromJson", &Weapon::registerWeaponsFromJson);
810 cls.addFunc("clearWeaponDefinitions", &Weapon::clearWeaponDefinitions);
811 cls.addFunc("getWeaponDefinitionCount", &Weapon::getWeaponDefinitionCount);
812 cls.addFunc("hasWeaponDefinition", &Weapon::hasWeaponDefinition);
813 cls.addFunc("getWeaponDefinitionLogic", &Weapon::getWeaponDefinitionLogic);
814 cls.addFunc("getWeaponDefinitionDamage", &Weapon::getWeaponDefinitionDamage);
815 cls.addFunc("getWeaponDefinitionRange", &Weapon::getWeaponDefinitionRange);
816 cls.addFunc("getLogicCount", [](Weapon*) -> int { return WeaponSystem::logicCount(); });
817 cls.addFunc("newWeapon", &Weapon::newWeapon);
818 cls.addFunc("newMount", &Weapon::newMount);
819 cls.addFunc("newRig", &Weapon::newRig);
820 cls.addFunc("rigAttachWeapon", &Weapon::rigAttachWeapon);
821 cls.addFunc("rigGetWeapon", &Weapon::rigGetWeapon);
822 cls.addFunc("rigSetPose", &Weapon::rigSetPose);
823 cls.addFunc("newAmmoPool", &Weapon::newAmmoPool);
824 cls.addFunc("ammoPoolAdd", &Weapon::ammoPoolAdd);
825 cls.addFunc("ammoPoolGetCount", &Weapon::ammoPoolGetCount);
826 cls.addFunc("bindAmmoPool", &Weapon::bindAmmoPool);
827 cls.addFunc("unbindAmmoPool", &Weapon::unbindAmmoPool);
828 cls.addFunc("getAmmoPool", &Weapon::getAmmoPool);
829 cls.addFunc("setFireMode", &Weapon::setFireMode);
830 cls.addFunc("getFireMode", &Weapon::getFireMode);
831 cls.addFunc("getSelectableModeCount", &Weapon::getSelectableModeCount);
832 cls.addFunc("getSelectableMode", &Weapon::getSelectableMode);
833 cls.addFunc("setAiming", &Weapon::setAiming);
834 cls.addFunc("isAiming", &Weapon::isAiming);
835 cls.addFunc("getZoomFov", &Weapon::getZoomFov);
836 cls.addFunc("getSpread", &Weapon::getSpread);
837 cls.addFunc("getRecoilPitch", &Weapon::getRecoilPitch);
838 cls.addFunc("getRecoilYaw", &Weapon::getRecoilYaw);
839 cls.addFunc("mountAttachWeapon", &Weapon::mountAttachWeapon);
840 cls.addFunc("mountGetWeapon", &Weapon::mountGetWeapon);
841 cls.addFunc("mountSetLimits", &Weapon::mountSetLimits);
842 cls.addFunc("mountAimAt", &Weapon::mountAimAt);
843 cls.addFunc("mountDestroy", &Weapon::mountDestroy);
844 cls.addFunc("fireAt", &Weapon::fireAt);
845 cls.addFunc("attack", &Weapon::attack);
846 cls.addFunc("canFire", &Weapon::canFire);
847 cls.addFunc("startReload", &Weapon::startReload);
848 cls.addFunc("cancelReload", &Weapon::cancelReload);
849 cls.addFunc("setAim", &Weapon::setAim);
850 cls.addFunc("update", &Weapon::update);
851 cls.addFunc("clearEvents", &Weapon::clearEvents);
852 cls.addFunc("getEventCount", &Weapon::getEventCount);
853 cls.addFunc("getEventType", &Weapon::getEventType);
854 cls.addFunc("getEventWeaponId", &Weapon::getEventWeaponId);
855 cls.addFunc("getEventDefId", &Weapon::getEventDefId);
856 cls.addFunc("getEventMountId", &Weapon::getEventMountId);
857 cls.addFunc("getEventAmmoLeft", &Weapon::getEventAmmoLeft);
858 cls.addFunc("getEventArc", &Weapon::getEventArc);
859 cls.addFunc("getEventAoe", &Weapon::getEventAoe);
860 cls.addFunc("getEventSpread", &Weapon::getEventSpread);
861 cls.addFunc("getEventPellets", &Weapon::getEventPellets);
862 cls.addFunc("getEventRecoilPitch", &Weapon::getEventRecoilPitch);
863 cls.addFunc("getEventRecoilYaw", &Weapon::getEventRecoilYaw);
864 cls.addFunc("getEventDamageType", &Weapon::getEventDamageType);
865 cls.addFunc("getEventElement", &Weapon::getEventElement);
866 cls.addFunc("getStage", &Weapon::getStage);
867 cls.addFunc("getResourceValue", &Weapon::getResourceValue);
869}
870
871} // namespace eve::weapon
double z
double y
double m[16]
double x
float w
Definition AnimClip.cpp:738
int root
Definition AnimSmr.cpp:119
float yaw
Definition BushMesh.cpp:37
struct SQVM * HSQUIRRELVM
glm::vec4 p[6]
HSQUIRRELVM vm
Definition ECS.cpp:38
HSQOBJECT cls
Definition ECS.cpp:39
std::string name
Definition ECS.cpp:154
std::vector< std::uint8_t > stored
Definition Evpack.cpp:171
glm::vec3 n
Definition Grass.cpp:63
double r
float v
int h
std::vector< Colorf > px
std::string id
Poco::JSON::Object::Ptr result
bool exists
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:27
double dt
Object::Ptr value
float d
RoadNetwork resolved
ScriptStructure out
std::string_view source
std::string kind
double current
std::string string
uint32_t index
Owning, renderer-independent dynamic values.
Selective canonical mana/stamina adapter for weapons.
Strongly typed Weapon definition/runtime adapter.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:177
std::map< std::string, Value > Object
Definition Value.h:34
std::vector< Value > Array
Definition Value.h:33
eve::ResultRef< const Definition > resolve(const std::string &type, const std::string &id) const
Resolves a definition through the common registry API.
eve::Result< DefinitionHandle > insert(const std::string &type, const std::string &id, int version, const std::string &json)
Inserts a definition using the common generation-qualified registry.
eve::Result< DefinitionHandle > replace(const std::string &type, const std::string &id, int version, const std::string &json)
Replaces a live definition and invalidates its previous handle.
eve::Result< DefinitionHandle > remove(const std::string &type, const std::string &id)
Removes a definition and returns the retained tombstone handle.
int countType(const std::string &type) const
Returns the number of definitions registered for a type.
const Definition * atType(const std::string &type, int index) const
Returns a definition by id order within one type, or nullptr.
共享弹药池实体:多把武器共用的备用弹药,装填时从池中取。
static AmmoPoolEntity * createPool()
创建并触摸全部组件。
Definition Weapon.cpp:155
武器逻辑接口:注册到 WeaponSystem 的可插拔行为。
Definition WeaponLogic.h:22
武器实体:数据全部在组件里,行为在 WeaponSystem。
static WeaponEntity * createWeapon()
创建并触摸全部组件。
Definition Weapon.cpp:129
武器挂点实体:可持有武器并限制旋转(炮塔 / 机枪座 / 固定挂架)。
static WeaponMountEntity * createMount()
创建并触摸全部组件。
Definition Weapon.cpp:139
手持位实体:面向 ARPG/RPG 角色手持武器(剑/法杖/步枪),无炮塔限位。
static WeaponRigEntity * createRig()
创建并触摸全部组件。
Definition Weapon.cpp:147
static void update(WeaponEntity &w, float dt)
每帧推进:冷却 / 连发 / 装填 / 炮口旋转 / 逻辑自身。
static bool canFire(WeaponEntity &w)
是否可开火(未装填/未卡壳/冷却完毕/有弹药/逻辑放行)。
static void registerLogic(IWeaponLogic *logic)
注册武器逻辑实现;同名替换。
static void setEventSink(WeaponEventSink sink)
注册事件汇(替换旧的;传 nullptr 清空)。
static void cancelReload(WeaponEntity &w)
打断装填。
static bool tryFire(WeaponEntity &w, const FireRequest &req)
尝试开火;满足条件时扣弹药、调逻辑、推事件并返回 true。
static void startReload(WeaponEntity &w)
开始装填(有备用弹药且弹匣不满时生效)。
static void emitEvent(const WeaponEvent &e)
向事件汇推一条事件(模块/脚本便捷入口)。
static int logicCount()
已注册逻辑数量。
武器模块(eve.Weapon)。
Definition Weapon.h:24
std::string getEventWeaponId(int index) const
Returns the event weapon id.
Definition Weapon.cpp:572
float getEventSpread(int index) const
P0 手感/伤害事件载荷(仅 fire 事件)。
Definition Weapon.cpp:596
bool fireAt(WeaponEntity *w, float x, float y, float z, int shooterId=0)
向目标点开火(自动生成 FireRequest)。
Definition Weapon.cpp:452
float getEventRecoilYaw(int index) const
Returns the event recoil yaw.
Definition Weapon.cpp:608
WeaponEntity * mountGetWeapon(WeaponMountEntity *m)
Returns the weapon mounted on a mount, or null when empty.
Definition Weapon.cpp:413
bool attack(WeaponEntity *w, float yaw, float pitch, int shooterId=0)
触发展开攻击(近战/法杖/导弹走阶段机;热武器等价 fire)。
Definition Weapon.cpp:463
bool mountAttachWeapon(WeaponMountEntity *m, WeaponEntity *w)
挂点操作:挂武器 / 取武器 / 限位 / 瞄准 / 击毁。
Definition Weapon.cpp:407
bool bindAmmoPool(WeaponEntity *w, AmmoPoolEntity *pool)
Binds ammo pool.
Definition Weapon.cpp:391
void unbindAmmoPool(WeaponEntity *w)
Unbinds ammo pool.
Definition Weapon.cpp:397
AmmoPoolEntity * getAmmoPool(WeaponEntity *w)
Returns the weapon's shared ammunition pool, or null when unbound.
Definition Weapon.cpp:401
void mountSetLimits(WeaponMountEntity *m, float yawMin, float yawMax, float pitchMin, float pitchMax, float rotSpeed, float firingArc)
Mounts set limits.
Definition Weapon.cpp:415
void update(float dt)
每帧推进全部武器与挂点。
Definition Weapon.cpp:546
std::string getStage(WeaponEntity *w) const
武器当前阶段("idle"|"windup"|"active"|"recover")。
Definition Weapon.cpp:620
bool setFireMode(WeaponEntity *w, const std::string &mode)
运行时射击模式切换(safe/semi/auto)。
Definition Weapon.cpp:492
std::string getEventType(int index) const
Returns the event type.
Definition Weapon.cpp:568
std::string getWeaponDefinitionLogic(const std::string &id)
Returns the weapon definition logic.
Definition Weapon.cpp:248
void startReload(WeaponEntity *w)
Starts reload.
Definition Weapon.cpp:478
std::string getFireMode(WeaponEntity *w)
当前射击模式名("single"|"burst"|"auto")。
Definition Weapon.cpp:507
float getWeaponDefinitionRange(const std::string &id)
Returns the weapon definition range.
Definition Weapon.cpp:266
std::string getEventElement(int index) const
Returns the event element.
Definition Weapon.cpp:616
void cancelReload(WeaponEntity *w)
Cancel reload.
Definition Weapon.cpp:482
bool fire(WeaponEntity *w, const FireRequest &req)
武器操作(脚本便捷入口,转发 WeaponSystem)。
Definition Weapon.cpp:450
WeaponRigEntity * newRig(const std::string &id, const std::string &wield="right_hand")
创建一个手持位(ARPG/RPG 角色手持武器)。
Definition Weapon.cpp:337
void clearWeaponDefinitions()
清空全部武器模板。
Definition Weapon.cpp:235
float getZoomFov(WeaponEntity *w)
开镜缩放 FOV(模板 zoomFov)。
Definition Weapon.cpp:535
std::string getSelectableMode(WeaponEntity *w, int index)
Returns the selectable mode.
Definition Weapon.cpp:516
float getSpread(WeaponEntity *w)
手感查询:当前散布 / 未回正后坐。
Definition Weapon.cpp:540
int getWeaponDefinitionCount()
已注册武器模板数量。
Definition Weapon.cpp:244
bool isAiming(WeaponEntity *w)
True when aiming.
Definition Weapon.cpp:533
WeaponMountEntity * newMount(const std::string &id, const std::string &type="turret")
创建一个挂点(炮塔/机枪座等)。
Definition Weapon.cpp:329
bool setAiming(WeaponEntity *w, bool aiming)
开镜(ADS):切换 aiming 状态并推 aim_in/aim_out 事件。
Definition Weapon.cpp:522
float getEventArc(int index) const
近战命中弧(仅 fire 事件)。
Definition Weapon.cpp:588
bool canFire(WeaponEntity *w)
Can fire.
Definition Weapon.cpp:476
WeaponEntity * rigGetWeapon(WeaponRigEntity *rig)
Rig get weapon.
Definition Weapon.cpp:355
int getEventAmmoLeft(int index) const
Returns the event ammo left.
Definition Weapon.cpp:584
float getEventAoe(int index) const
法术/导弹爆炸半径(仅 fire 事件)。
Definition Weapon.cpp:592
std::string getEventMountId(int index) const
Returns the event mount id.
Definition Weapon.cpp:580
float getResourceValue(WeaponEntity *w) const
武器当前资源值(弹药/法力/充能/体力)。
Definition Weapon.cpp:624
int getEventCount() const
Returns the event count.
Definition Weapon.cpp:566
void setAim(WeaponEntity *w, float yaw, float pitch)
Sets the aim.
Definition Weapon.cpp:486
AmmoPoolEntity * newAmmoPool(const std::string &id, const std::string &ammoType, int max=-1)
共享弹药池操作:创建 / 补弹 / 查询 / 绑定武器 / 解绑 / 取绑定池。
Definition Weapon.cpp:371
int getEventPellets(int index) const
Returns the event pellets.
Definition Weapon.cpp:600
float getRecoilYaw(WeaponEntity *w)
Returns the recoil yaw.
Definition Weapon.cpp:544
int registerWeaponsFromJson(const std::string &json)
从 JSON 注册武器模板;返回成功注册数量。
Definition Weapon.cpp:184
int ammoPoolGetCount(AmmoPoolEntity *pool)
Ammo pool get count.
Definition Weapon.cpp:389
bool rigAttachWeapon(WeaponRigEntity *rig, WeaponEntity *w)
手持位操作:挂武器 / 取武器 / 设置持有位姿。
Definition Weapon.cpp:349
~Weapon() override
Weapon.
Definition Weapon.cpp:171
void mountAimAt(WeaponMountEntity *m, float yaw, float pitch)
按限位夹取目标角并写入挂载武器的瞄准目标(角度,度)。
Definition Weapon.cpp:426
bool hasWeaponDefinition(const std::string &id)
武器模板查询。
Definition Weapon.cpp:246
static int getLogicCount()
已注册逻辑数量(内置 hitscan / projectile 起步)。
Definition Weapon.cpp:277
void clearEvents()
事件队列(fire/reload/empty,上一次 update 产生)。
Definition Weapon.cpp:564
float getWeaponDefinitionDamage(const std::string &id)
Returns the weapon definition damage.
Definition Weapon.cpp:257
std::string getEventDefId(int index) const
Returns the event def id.
Definition Weapon.cpp:576
float getEventRecoilPitch(int index) const
Returns the event recoil pitch.
Definition Weapon.cpp:604
WeaponEntity * newWeapon(const std::string &defId)
工厂:对象由 ECS 表持有,脚本持有的是非拥有句柄。
Definition Weapon.cpp:289
float getRecoilPitch(WeaponEntity *w)
Returns the recoil pitch.
Definition Weapon.cpp:542
void rigSetPose(WeaponRigEntity *rig, float px, float py, float pz, float rx, float ry, float rz)
Rig set pose.
Definition Weapon.cpp:357
std::string getEventDamageType(int index) const
Returns the event damage type.
Definition Weapon.cpp:612
static void registerLogic(IWeaponLogic *logic)
注册武器逻辑(C++ 插件/游戏侧扩展点;同名替换)。
Definition Weapon.cpp:275
int getSelectableModeCount(WeaponEntity *w)
可选射击模式数量 / 第 index 个模式名。
Definition Weapon.cpp:511
void mountDestroy(WeaponMountEntity *m)
标记挂点被击毁(炮塔被打掉);已毁挂点不再瞄准/开火。
Definition Weapon.cpp:441
void ammoPoolAdd(AmmoPoolEntity *pool, int n)
Ammo pool add.
Definition Weapon.cpp:380
std::unordered_map< std::string, SkillDefinition > & table()
Definition Skill.cpp:73
载具模块入口(eve.Vehicle):定义注册 / 实体工厂 / RTS 命令 / 帧调度。 设计文档:docs/dev/通用载具系统设计.md
WeaponKind
武器形态。
Definition WeaponTypes.h:34
const char * weaponKindName(WeaponKind kind)
武器形态的字符串名("melee" | "ranged" | "magic" | "missile" | "custom")。
Definition Weapon.cpp:86
eve::Result< WeaponDefinition > parseWeaponDefinition(const eve::definitions::Definition &source)
Parse one canonical registry definition into an owning typed snapshot.
WeaponKind weaponKindFromName(const std::string &name)
从字符串解析武器形态;未知名字回退 Ranged。
Definition Weapon.cpp:97
void exposeCombatCarrierModuleMethods(ssq::Class &cls)
Register Weapon module methods that create owned carrier runtimes.
FireMode fireModeFromName(const std::string &name)
从字符串解析开火模式;未知名字回退 Single。
Definition Weapon.cpp:80
AttackStage
攻击阶段。
Definition WeaponTypes.h:62
void declareScriptProjectileSeam()
声明 IProjectileService 的脚本绑定接缝。
void withdrawScriptProjectileSeam()
撤回本模块声明的脚本接缝,并卸载全部脚本提供方。
void exposeCombatCarrierBindings(ssq::Table &table)
Expose CombatCarrierRuntime class bindings under the shared eve table.
FireMode
开火模式(热武器保留字段)。
Definition WeaponTypes.h:82
const char * weaponEventTypeName(WeaponEventType type)
事件类型的字符串名。
Definition Weapon.cpp:115
const char * fireModeName(FireMode mode)
开火模式的字符串名("single" | "burst" | "auto")。
Definition Weapon.cpp:71
WeaponEventType
武器事件类型。
Definition WeaponTypes.h:98
const char * attackStageName(AttackStage stage)
攻击阶段的字符串名("idle" | "windup" | "active" | "recover")。
Definition Weapon.cpp:105
detail::StrongUint64< detail::SchemaVersionTag > SchemaVersion
Persistent data-format version; not a runtime replacement generation.
void registerCppEntityView(const ssq::Class &cls, CppEntityViewFn fn)
Registers cpp entity view.
Definition ECS.cpp:1642
One immutable view of a registered versioned JSON definition.
Definition Definitions.h:31
一次攻击请求(C++ 系统 / 脚本发起)。角度均为度。 旧名 FireRequest 保留为别名,向后兼容。
int shooterId
游戏侧实体/玩家 id。
float yaw
发射方向(度)。
float arcAngle
近战挥击命中弧(度)。
float aoeRadius
法术/导弹爆炸半径。
运行时触发资源(实体组件)。
武器模板(registerWeaponsFromJson 注册,进程级注册表)。
AttackResource resource
触发资源(弹药 / 法力 / 充能 / 体力 / 无)。
float zoomFov
开镜缩放 FOV(0 = 无缩放);State.aiming 时生效。
WeaponKind kind
形态(决定阶段机如何跑)。默认 Ranged。
int magSize
弹匣容量 / 备用弹药(<0 = 无限备用,0 = 无备用)。热武器保留字段。
float spreadMin
散布 bloom:连续射击精度下降,停火回稳。
武器事件(帧缓存,脚本轮询,与 building/rpg 风格一致)。