载入中...
搜索中...
未找到
WeaponTypes.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
23#include "common/ECS.h"
25
26#include <cstdint>
27#include <memory>
28#include <string>
29#include <vector>
30
31namespace eve::weapon {
32
34enum class WeaponKind : uint8_t { Melee, Ranged, Magic, Missile, Custom };
35
45
48
50enum class ResourceKind : uint8_t { None, Ammo, Mana, Charges, Stamina };
51
55 float max = 0.f;
56 float regen = 0.f; // >0 时每秒回复(法力 / 充能)
57 float cost = 0.f; // 每次触发消耗
58 bool infinite = false; // 无消耗(近战默认)
59};
60
62enum class AttackStage : uint8_t { Idle, Windup, Active, Recover };
63
72const char* attackStageName(AttackStage stage);
73
76 float windupTime = 0.f; // 前摇(挥剑起手 / 施法抬手 / 导弹锁定)
77 float activeTime = 0.f; // 生效期(命中帧 / 引导节拍 / 发射时刻)
78 float recoverTime = 0.f; // 后摇(收刀 / 施法硬直 / 再装填窗口)
79};
80
82enum class FireMode : uint8_t { Single, Burst, Auto };
83
92const char* fireModeName(FireMode mode);
93
95FireMode fireModeFromName(const std::string& name);
96
98enum class WeaponEventType : uint8_t {
99 Fire,
101 ReloadEnd,
102 Empty,
104 AttackEnd,
105 AimIn,
106 AimOut
107};
108
118
121 std::string type = "shell";
122 float speed = 0.f;
123 float gravity = 0.f;
124 float aoe = 0.f;
126 int pelletCount = 1;
128 float pelletSpread = 0.f;
129};
130
133 std::string id;
137 std::string logic = "projectile";
138 float damage = 0.f;
139 float penetration = 0.f;
140 float range = 0.f;
142 float falloffStart = 0.f;
147 float accuracy = 1.0f;
149 float scatterRadius = 0.0f;
151 float spread = 0.f;
153 float spreadMin = 0.f; // 静止散布(度)
154 float spreadMax = 0.f; // 连射上限散布(度)
155 float spreadPerShot = 0.f; // 每发增量(度)
156 float spreadRecover = 0.f; // 每秒回稳速度(度/秒)
158 float recoilPitch = 0.f; // 每发上抬(度)
159 float recoilYaw = 0.f; // 每发水平(度)
160 float recoilRecover = 0.f; // 每秒回正速度(度/秒)
162 std::string damageType;
163 std::string element;
165 bool targetsGround = true;
166 bool targetsAir = true;
167 bool friendlyFire = false;
168 bool blockedByObstacles = false;
169 std::vector<std::string> requiredTargetTags;
170 std::vector<std::string> excludedTargetTags;
172 std::vector<std::string> preferredTargetTags;
175 std::vector<FireMode> selectableModes; // 空 = 固定 fireMode
177 float zoomFov = 0.f;
180 float cooldown = 0.f;
182 int burstSize = 1;
183 float burstInterval = 0.f;
189 float arc = 0.f;
191 int magSize = 1;
192 int reserveSize = 0;
193 float reloadTime = 0.f;
196 std::string effectMuzzle;
197 std::string effectSound;
198};
199
205 float targetX = 0.f;
206 float targetY = 0.f;
207 float targetZ = 0.f;
208 bool hasTarget = false;
210 ecs::EntityHandle targetHandle;
212 float muzzleX = 0.f;
213 float muzzleY = 0.f;
214 float muzzleZ = 0.f;
216 float yaw = 0.f;
217 float pitch = 0.f;
219 int shooterId = 0;
221 float arcAngle = 0.f;
223 float aoeRadius = 0.f;
225 float spread = 0.f;
227 int pelletIndex = 0;
228 int pelletCount = 1;
229};
230
233
237 std::string weaponId;
238 std::string defId;
239 std::string mountId;
240 int ammoLeft = 0;
242 float x = 0.f;
243 float y = 0.f;
244 float z = 0.f;
246 float arc = 0.f;
248 float aoe = 0.f;
250 float spread = 0.f;
252 float recoilPitch = 0.f;
253 float recoilYaw = 0.f;
255 int pellets = 1;
257 std::string damageType;
258 std::string element;
259};
260
262struct Resource {
264 float value = 0.f; // 当前值(弹匣剩余 / 法力 / 充能 / 体力)
265 float max = 0.f;
266 float regen = 0.f;
267 float cost = 0.f;
268 bool infinite = false;
270 int reserve = 0;
271 bool reloading = false;
272 float reloadProgress = 0.f;
273};
274
276class EVENGINE_API_WORLD WeaponEntity : public ecs::Entity {
277public:
279 ENTITY(WeaponEntity, ecs::Entity)
280
281
282 void release() override { ecs::DestroyEntity(this); }
283
285 struct Identity {
286 std::string id;
287 std::string defId;
288 int ownerId = 0;
289 };
290
300 struct Definition {
301 const WeaponDefinition* def = nullptr;
303 std::shared_ptr<const WeaponDefinition> owned;
304 };
305
318
320 struct State {
322 float cooldown = 0.f; // 热武器额外冷却
323 int burstRemaining = 0;
324 float burstTimer = 0.f;
325 bool jammed = false;
326 AttackStage stage = AttackStage::Idle;
327 float stageTimer = 0.f;
331 const AttackStageSpec* stages = nullptr;
333 float currentSpread = 0.f;
335 float recoilPitch = 0.f;
336 float recoilYaw = 0.f;
338 FireMode selector = FireMode::Single;
340 bool aiming = false;
342 class AmmoPoolEntity* ammoPool = nullptr;
343 };
344
355
357 struct Aim {
358 float yaw = 0.f;
359 float pitch = 0.f;
360 float desiredYaw = 0.f;
361 float desiredPitch = 0.f;
362 float turnSpeed = 0.f;
363 };
364
365 COMPONENT(Identity, identity)
366 COMPONENT(Definition, definition)
367 COMPONENT(DefinitionBinding, definitionBinding)
368 COMPONENT(State, state)
369 COMPONENT(Attributes, attributes)
370 COMPONENT(Aim, aim)
371
372
380 static WeaponEntity* createWeapon();
381};
382
384class WeaponMountEntity : public ecs::Entity {
385public:
387 ENTITY(WeaponMountEntity, ecs::Entity)
388
389
390 void release() override { ecs::DestroyEntity(this); }
391
393 struct Identity {
394 std::string id;
395 std::string nodePath;
396 std::string type = "turret";
397 };
398
400 struct Limits {
401 float yawMin = -180.f;
402 float yawMax = 180.f;
403 float pitchMin = -45.f;
404 float pitchMax = 45.f;
406 float rotSpeed = 0.f;
408 float firingArc = 0.f;
409 };
410
412 struct State {
414 float yaw = 0.f;
415 float pitch = 0.f;
416 bool destroyed = false;
417 };
418
419 COMPONENT(Identity, identity)
420 COMPONENT(Limits, limits)
421 COMPONENT(State, state)
422
423
432};
433
435class WeaponRigEntity : public ecs::Entity {
436public:
438 ENTITY(WeaponRigEntity, ecs::Entity)
439
440
441 void release() override { ecs::DestroyEntity(this); }
442
444 struct Identity {
445 std::string id;
446 std::string nodePath;
447 std::string wield = "right_hand";
448 };
449
451 struct Held {
452 float posX = 0.f;
453 float posY = 0.f;
454 float posZ = 0.f;
455 float rotX = 0.f;
456 float rotY = 0.f;
457 float rotZ = 0.f;
458 };
459
461 struct State {
463 };
464
465 COMPONENT(Identity, identity)
466 COMPONENT(Held, held)
467 COMPONENT(State, state)
468
469
477 static WeaponRigEntity* createRig();
478};
479
481class AmmoPoolEntity : public ecs::Entity {
482public:
484 ENTITY(AmmoPoolEntity, ecs::Entity)
485
486
487 void release() override { ecs::DestroyEntity(this); }
488
490 struct Identity {
491 std::string id;
492 std::string ammoType;
493 };
494
496 struct State {
497 int count = 0;
498 int max = -1;
499 };
500
501 COMPONENT(Identity, identity)
502 COMPONENT(State, state)
503
504
512 static AmmoPoolEntity* createPool();
513};
514
515} // namespace eve::weapon
bool & active
Owner-aware canonical attribute state shared by gameplay adapters.
Common identity and hot-reload contract for typed runtime instances.
#define EVENGINE_API_WORLD
Definition Export.h:109
TokenKind kind
std::string name
std::function< eve::Result< void >()> release
Definition Procgen.cpp:86
LogicalId definition
const AssetImportLimits & limits
Canonical selected-attribute storage with owner and revision checks.
共享弹药池实体:多把武器共用的备用弹药,装填时从池中取。
void release() override
Entity.
static AmmoPoolEntity * createPool()
创建并触摸全部组件。
Definition Weapon.cpp:155
武器实体:数据全部在组件里,行为在 WeaponSystem。
武器挂点实体:可持有武器并限制旋转(炮塔 / 机枪座 / 固定挂架)。
void release() override
Entity.
static WeaponMountEntity * createMount()
创建并触摸全部组件。
Definition Weapon.cpp:139
手持位实体:面向 ARPG/RPG 角色手持武器(剑/法杖/步枪),无炮塔限位。
static WeaponRigEntity * createRig()
创建并触摸全部组件。
Definition Weapon.cpp:147
void release() override
Entity.
ReloadPolicy
Policy used when a live definition is replaced.
@ RebuildInstance
Let the consumer atomically construct a new state from the new definition.
载具模块入口(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
WeaponKind weaponKindFromName(const std::string &name)
从字符串解析武器形态;未知名字回退 Ranged。
Definition Weapon.cpp:97
FireMode fireModeFromName(const std::string &name)
从字符串解析开火模式;未知名字回退 Single。
Definition Weapon.cpp:80
AttackStage
攻击阶段。
Definition WeaponTypes.h:62
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
ResourceKind
触发资源的类型。
Definition WeaponTypes.h:50
Canonical identity carried by every typed runtime instance.
弹药池 id / 弹药类型("pistol" | "rifle" | "shell"…)。
当前存量 / 上限(<0 = 无限)。
一次攻击请求(C++ 系统 / 脚本发起)。角度均为度。 旧名 FireRequest 保留为别名,向后兼容。
int pelletIndex
多弹丸:本粒序号 / 总粒数(1 = 单弹丸)。
float muzzleX
炮口世界位置(未提供时游戏侧自行推断)。
float spread
本发实际散布(度,散布 bloom 后的当前值)。
int shooterId
游戏侧实体/玩家 id。
ecs::EntityHandle targetHandle
可选目标实体(导弹锁定 / 法杖单目标)。
float yaw
发射方向(度)。
float arcAngle
近战挥击命中弧(度)。
float aoeRadius
法术/导弹爆炸半径。
触发资源模板(武器模板的一部分,用于运行时扣费 / 回复)。
Definition WeaponTypes.h:53
阶段时长(秒);各形态按需配置。
Definition WeaponTypes.h:75
投射物参数(武器模板的一部分,供游戏侧投射物服务使用)。
int pelletCount
单次触发弹丸数(霰弹 >1);1 = 单弹丸。
float pelletSpread
每粒相对中心的散布(度),仅 pelletCount>1 时生效。
运行时触发资源(实体组件)。
int reserve
备用弹药(热武器;<0 = 无限)。
武器模板(registerWeaponsFromJson 注册,进程级注册表)。
AttackStageSpec stages
阶段机时长(秒)。
AttackResource resource
触发资源(弹药 / 法力 / 充能 / 体力 / 无)。
float zoomFov
开镜缩放 FOV(0 = 无缩放);State.aiming 时生效。
float scatterRadius
Maximum world-space miss displacement for an inaccurate shot.
float spread
散布(度)。
std::string logic
IWeaponLogic 注册名;默认 "projectile"。
std::vector< std::string > preferredTargetTags
Soft automatic-target role hints; explicit attacks remain authoritative.
float splashMinimumDamageFactor
Minimum radial multiplier at the outer edge of projectile area damage.
std::vector< std::string > excludedTargetTags
WeaponKind kind
形态(决定阶段机如何跑)。默认 Ranged。
float accuracy
Probability of a shot retaining its intended target.
float cooldown
单次开火后的冷却(秒);热武器保留字段。
float recoilPitch
后坐力模型:每发累积,游戏侧读事件做相机/枪口表现。
std::vector< FireMode > selectableModes
运行时射击模式(safe/semi/auto 切换)。
std::vector< std::string > requiredTargetTags
float falloffStart
Linear range falloff begins here and reaches minimumDamageFactor at range.
bool targetsGround
Shared target-domain and gameplay-tag acceptance policy.
std::string effectMuzzle
特效/音效资源 id(引擎不播放,游戏侧读事件播放)。
int magSize
弹匣容量 / 备用弹药(<0 = 无限备用,0 = 无备用)。热武器保留字段。
std::string damageType
伤害类型 / 元素(游戏侧结算用,引擎只透传)。
int burstSize
burst 模式的连发数与发间间隔(秒)。
float spreadMin
散布 bloom:连续射击精度下降,停火回稳。
float arc
近战挥击命中弧(度)。
炮口朝向(度)。turnSpeed 0 = 立即到位。
Canonical optional mana/stamina state for non-ammo weapons.
eve::attributes::AttributeProjection values
Canonical definition identity and reload policy projected to ECS. @ownership The common DefinitionReg...
eve::definition::InstanceIdentity identity
Typed definition projection used by legacy WeaponSystem code. @ownership Borrowed through def when ow...
std::shared_ptr< const WeaponDefinition > owned
Immutable typed projection owner installed by checked adapters.
稳定实例 id / 模板 id / 游戏侧拥有者。
触发资源 / 冷却 / 装填 / 阶段机运行时状态。
AttackRequest lastRequest
阶段期间保存的攻击请求(供 Active/channel 使用)。
武器事件(帧缓存,脚本轮询,与 building/rpg 风格一致)。
float x
发射位置(仅 Fire 事件填写)。
float arc
近战命中弧(仅 Fire 事件填写)。
std::string damageType
伤害类型 / 元素(游戏侧结算用)。
int pellets
本发弹丸数(霰弹 >1)。
float recoilPitch
本发后坐(度,仅 Fire 事件)。
float aoe
法术/导弹爆炸半径(仅 Fire 事件填写)。
float spread
本发当前散布(度,仅 Fire 事件)。
挂点 id / 场景节点路径 / 类型("turret" | "pintle" | "fixed")。
旋转限位与射界(度)。
float firingArc
RTS 射界(度,0 = 360° 全向)。
float rotSpeed
旋转速度(度/秒);0 = 立即。
当前朝向(度)与挂载的武器(不拥有,模块负责两者生命周期)。
持有位姿偏移(挂到角色手持节点的相对位置/旋转)。
手持位 id / 场景节点路径 / 握持类型。
当前持有的武器(不拥有,模块负责生命周期)。