Привет всем! Пишу свой мод, задумка которого "аренда" домов. Для удовбства использую яблока как клас который можно будет потом заменить. И вот запутался. Столкнулся с тем, что при соблюдении всех условия (яблоко в руках), меню взаимодействия с объектом нет. Помогите разобраться.
Структура мода:
@HouseLockSystem
├── Config.cpp
├── meta.cpp
└── Scripts
└── 4_World
├── HouseCore.c
├── HouseApple.c
├── HouseWrench.c
└── HouseDoors.c
Config.cpp
class CfgMods {
class HouseLockSystem {
dir = "HouseLockSystem";
name = "House Lock System";
author = "https://steamcommunity.com/profiles/76561199218849472/";
version = 2.1;
dependencies[] = {"Game", "World", "Mission"};
class defs {
class gameScriptModule {
files[] = {"HouseLockSystem/Scripts/4_World"};
};
class worldScriptModule {
files[] = {"HouseLockSystem/Scripts/4_World"};
};
class missionScriptModule {
files[] = {"HouseLockSystem/Scripts/4_World"};
};
};
};
};
class CfgScripts {
class HouseLockSystem_Init {
postInit = 1;
init = "HouseLockSystem\Scripts\4_World\HouseCore.c";
};
};
HouseCore.c
class HouseCore {
protected static ref HouseCore m_Instance;
protected ref map<string, ref HouseData> m_Houses;
protected ref map<string, ref BreachData> m_Breaches;
protected string m_DataFile = "$profile/HouseData.json";
// Singleton
static HouseCore Get() {
if (!m_Instance) m_Instance = new HouseCore();
return m_Instance;
}
void HouseCore() {
m_Houses = new map<string, ref HouseData>();
m_Breaches = new map<string, ref BreachData>();
LoadData();
ScheduleChecks();
}
void ScheduleChecks() {
GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(CheckHouseExpiry, 30000, true);
GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(CheckBreachProgress, 1000, true);
}
void CheckHouseExpiry() {
int currentTime = GetGame().GetTime();
foreach (string houseID, HouseData data: m_Houses) {
if (currentTime > data.m_ExpireTime) ReleaseHouse(houseID);
}
}
void CheckBreachProgress() {
int currentTime = GetGame().GetTime();
foreach (string houseID, BreachData data: m_Breaches) {
if (currentTime - data.m_StartTime > 1200) CompleteBreach(houseID);
}
}
void ReleaseHouse(string houseID) {
if (m_Houses.Contains(houseID)) {
OpenAllDoors(m_Houses.Get(houseID).m_Position);
m_Houses.Remove(houseID);
SaveData();
}
}
void CompleteBreach(string houseID) {
if (m_Breaches.Contains(houseID)) {
OpenAllDoors(m_Houses.Get(houseID).m_Position);
m_Breaches.Remove(houseID);
}
}
string GenerateHouseID(vector pos) {
return pos.ToString().Substring(0, 16);
}
bool ClaimHouse(PlayerBase player, vector pos) {
string uid = player.GetIdentity().GetId();
string houseID = GenerateHouseID(pos);
if (m_Houses.Contains(houseID)) {
player.MessageAction("Дом уже занят!");
return false;
}
if (GetPlayerHouseCount(uid) >= 1) {
player.MessageAction("Можно иметь только 1 дом!");
return false;
}
m_Houses.Insert(houseID, new HouseData(uid, GetGame().GetTime() + 604800, pos));
SaveData();
return true;
}
void StartBreach(PlayerBase player, vector pos) {
string houseID = GenerateHouseID(pos);
if (!m_Breaches.Contains(houseID)) {
m_Breaches.Insert(houseID, new BreachData());
}
}
};
HouseApple.c
modded class Apple {
override bool CanBeTargeted() { return true; }
override string GetActionText(Object target) {
if (target.IsInherited(Building)) return "Закрепить дом";
return super.GetActionText(target);
}
override void OnAction(PlayerBase player, Object target, int action) {
super.OnAction(player, target, action);
if (action == UA_USE && target.IsInherited(Building)) {
vector pos = target.GetPosition();
if (HouseCore.Get().ClaimHouse(player, pos)) {
player.MessageAction("Дом зарезервирован на 7 дней!");
Delete();
}
}
}
};
HouseWrench.c
modded class Wrench {
override bool CanBeTargeted() { return true; }
override string GetActionText(Object target) {
if (target.IsInherited(Building)) return "Взломать (20 мин)";
return super.GetActionText(target);
}
override void OnAction(PlayerBase player, Object target, int action) {
super.OnAction(player, target, action);
if (action == UA_USE && target.IsInherited(Building)) {
HouseCore.Get().StartBreach(player, target.GetPosition());
player.MessageAction("Начался процесс взлома...");
}
}
};
HouseDoors.c
modded class Building {
override bool CanInteractWith(PlayerBase player, ActionTarget target) {
HouseCore core = HouseCore.Get();
string houseID = core.GenerateHouseID(GetPosition());
// Для владельца
if (core.m_Houses.Contains(houseID) &&
core.m_Houses.Get(houseID).m_OwnerUID == player.GetIdentity().GetId()) {
return true;
}
// Для взломщиков
if (core.m_Breaches.Contains(houseID)) {
return true;
}
return super.CanInteractWith(player, target);
}
override void CloseDoor(int index) {
super.CloseDoor(index);
HouseCore.Get().SaveDoorState(GetPosition(), index, true);
}
override void OpenDoor(int index) {
super.OpenDoor(index);
HouseCore.Get().SaveDoorState(GetPosition(), index, false);
}
};