载入中...
搜索中...
未找到
Weapon.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
10#include "common/BorrowedRef.h"
11#include "common/ECS.h"
12#include "common/Module.h"
15#include "weapon/WeaponLogic.h"
16#include "weapon/WeaponTypes.h"
17
18#include <string>
19#include <vector>
20
21namespace eve::weapon {
22
25public:
28 Weapon();
30 ~Weapon() override;
31
33 int registerWeaponsFromJson(const std::string& json);
35 void clearWeaponDefinitions();
37 int getWeaponDefinitionCount();
39 bool hasWeaponDefinition(const std::string& id);
41 std::string getWeaponDefinitionLogic(const std::string& id);
43 float getWeaponDefinitionDamage(const std::string& id);
45 float getWeaponDefinitionRange(const std::string& id);
46
54 [[nodiscard]] eve::definitions::DefinitionRegistry& definitionRegistry() noexcept { return definitionRegistry_; }
55
57 static void registerLogic(IWeaponLogic* logic);
59 static int getLogicCount();
60
69 WeaponEntity* newWeapon(const std::string& defId);
78 WeaponMountEntity* newMount(const std::string& id, const std::string& type = "turret");
87 WeaponRigEntity* newRig(const std::string& id, const std::string& wield = "right_hand");
88
90 bool rigAttachWeapon(WeaponRigEntity* rig, WeaponEntity* w);
92 WeaponEntity* rigGetWeapon(WeaponRigEntity* rig);
94 void rigSetPose(WeaponRigEntity* rig, float px, float py, float pz, float rx, float ry, float rz);
95
105 AmmoPoolEntity* newAmmoPool(const std::string& id, const std::string& ammoType, int max = -1);
107 void ammoPoolAdd(AmmoPoolEntity* pool, int n);
109 int ammoPoolGetCount(AmmoPoolEntity* pool);
111 bool bindAmmoPool(WeaponEntity* w, AmmoPoolEntity* pool);
113 void unbindAmmoPool(WeaponEntity* w);
122 AmmoPoolEntity* getAmmoPool(WeaponEntity* w);
123
125 bool mountAttachWeapon(WeaponMountEntity* m, WeaponEntity* w);
134 WeaponEntity* mountGetWeapon(WeaponMountEntity* m);
136 void mountSetLimits(WeaponMountEntity* m, float yawMin, float yawMax, float pitchMin, float pitchMax,
137 float rotSpeed, float firingArc);
139 void mountAimAt(WeaponMountEntity* m, float yaw, float pitch);
141 void mountDestroy(WeaponMountEntity* m);
142
144 bool fire(WeaponEntity* w, const FireRequest& req);
146 bool fireAt(WeaponEntity* w, float x, float y, float z, int shooterId = 0);
148 bool attack(WeaponEntity* w, float yaw, float pitch, int shooterId = 0);
150 bool canFire(WeaponEntity* w);
152 void startReload(WeaponEntity* w);
154 void cancelReload(WeaponEntity* w);
156 void setAim(WeaponEntity* w, float yaw, float pitch);
157
159 bool setFireMode(WeaponEntity* w, const std::string& mode);
161 std::string getFireMode(WeaponEntity* w);
163 int getSelectableModeCount(WeaponEntity* w);
165 std::string getSelectableMode(WeaponEntity* w, int index);
166
168 bool setAiming(WeaponEntity* w, bool aiming);
170 bool isAiming(WeaponEntity* w);
172 float getZoomFov(WeaponEntity* w);
174 float getSpread(WeaponEntity* w);
176 float getRecoilPitch(WeaponEntity* w);
178 float getRecoilYaw(WeaponEntity* w);
179
181 void update(float dt);
182
184 void clearEvents();
186 int getEventCount() const;
188 std::string getEventType(int index) const;
190 std::string getEventWeaponId(int index) const;
192 std::string getEventDefId(int index) const;
194 std::string getEventMountId(int index) const;
196 int getEventAmmoLeft(int index) const;
198 float getEventArc(int index) const;
200 float getEventAoe(int index) const;
202 float getEventSpread(int index) const;
204 int getEventPellets(int index) const;
206 float getEventRecoilPitch(int index) const;
208 float getEventRecoilYaw(int index) const;
210 std::string getEventDamageType(int index) const;
212 std::string getEventElement(int index) const;
214 std::string getStage(WeaponEntity* w) const;
216 float getResourceValue(WeaponEntity* w) const;
217
218private:
234 [[nodiscard]] eve::Result<WeaponDefinition> findDef(const std::string& id) const;
235
236 eve::definitions::DefinitionRegistry definitionRegistry_;
237 std::vector<ecs::EntityHandle> weapons_;
238 std::vector<ecs::EntityHandle> mounts_;
239 std::vector<ecs::EntityHandle> rigs_;
240 std::vector<ecs::EntityHandle> pools_;
241 std::vector<WeaponEvent> events_;
242 int nextInstance_ = 1;
243};
244
245} // namespace eve::weapon
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
Vocabulary aliases for nullable and checked borrowed references.
float py
float pz
#define EVENGINE_API_WORLD
Definition Export.h:109
glm::vec3 n
Definition Grass.cpp:63
std::vector< Colorf > px
uint32_t index
float m[16]
Strongly typed Weapon definition/runtime adapter.
EVENGINE_API_FOUNDATION public API.
Definition Module.h:46
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Deterministic registry of topic-neutral, versioned JSON definitions.
Definition Definitions.h:58
共享弹药池实体:多把武器共用的备用弹药,装填时从池中取。
武器逻辑接口:注册到 WeaponSystem 的可插拔行为。
Definition WeaponLogic.h:22
武器实体:数据全部在组件里,行为在 WeaponSystem。
武器挂点实体:可持有武器并限制旋转(炮塔 / 机枪座 / 固定挂架)。
手持位实体:面向 ARPG/RPG 角色手持武器(剑/法杖/步枪),无炮塔限位。
武器模块(eve.Weapon)。
Definition Weapon.h:24
eve::definitions::DefinitionRegistry & definitionRegistry() noexcept
Return the common registry backing legacy weapon definitions.
Definition Weapon.h:54
载具模块入口(eve.Vehicle):定义注册 / 实体工厂 / RTS 命令 / 帧调度。 设计文档:docs/dev/通用载具系统设计.md
一次攻击请求(C++ 系统 / 脚本发起)。角度均为度。 旧名 FireRequest 保留为别名,向后兼容。