Skip to content

Commit

Permalink
feat: start car races if you "equip" the car near the car pad; add mo…
Browse files Browse the repository at this point in the history
…re old ns scripts to ignore list (#1681)

* brother

* use some better logic

* Implement spider boss msg script

tested that the message now shows up when hitting the survival spider entrance area

* add drag to start race feature
  • Loading branch information
EmosewaMC authored Dec 18, 2024
1 parent a60865c commit 15dc5fe
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 36 deletions.
25 changes: 25 additions & 0 deletions dGame/dComponents/InventoryComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "eStateChangeType.h"
#include "eUseItemResponse.h"
#include "Mail.h"
#include "ProximityMonitorComponent.h"

#include "CDComponentsRegistryTable.h"
#include "CDInventoryComponentTable.h"
Expand Down Expand Up @@ -829,6 +830,30 @@ void InventoryComponent::EquipItem(Item* item, const bool skipChecks) {
break;
}

return;
} else if (item->GetLot() == 8092) {
// Trying to equip a car
const auto proximityObjects = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::PROXIMITY_MONITOR);

// look for car instancers and check if we are in its setup range
for (auto* const entity : proximityObjects) {
if (!entity) continue;

auto* proximityMonitorComponent = entity->GetComponent<ProximityMonitorComponent>();
if (!proximityMonitorComponent) continue;

if (proximityMonitorComponent->IsInProximity("Interaction_Distance", m_Parent->GetObjectID())) {
// in the range of a car instancer
entity->OnUse(m_Parent);
GameMessages::UseItemOnClient itemMsg;
itemMsg.target = entity->GetObjectID();
itemMsg.itemLOT = item->GetLot();
itemMsg.itemToUse = item->GetId();
itemMsg.playerId = m_Parent->GetObjectID();
itemMsg.Send(m_Parent->GetSystemAddress());
break;
}
}
return;
}

Expand Down
81 changes: 51 additions & 30 deletions dGame/dGameMessages/GameMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6342,36 +6342,57 @@ void GameMessages::SendUpdateInventoryUi(LWOOBJID objectId, const SystemAddress&
SEND_PACKET;
}

void GameMessages::DisplayTooltip::Send() const {
CBITSTREAM;
CMSGHEADER;
namespace GameMessages {
void GameMsg::Send(const SystemAddress& sysAddr) const {
CBITSTREAM;
CMSGHEADER;

bitStream.Write(target);
bitStream.Write(msgId);

bitStream.Write(doOrDie);
bitStream.Write(noRepeat);
bitStream.Write(noRevive);
bitStream.Write(isPropertyTooltip);
bitStream.Write(show);
bitStream.Write(translate);
bitStream.Write(time);
bitStream.Write<int32_t>(id.size());
bitStream.Write(id);

std::string toWrite;
for (const auto* item : localizeParams) {
toWrite += item->GetString() + "\n";
}
if (!toWrite.empty()) toWrite.pop_back();
bitStream.Write<int32_t>(toWrite.size());
bitStream.Write(GeneralUtils::ASCIIToUTF16(toWrite));
if (!toWrite.empty()) bitStream.Write<uint16_t>(0x00); // Null Terminator

bitStream.Write<int32_t>(imageName.size());
bitStream.Write(imageName);
bitStream.Write<int32_t>(text.size());
bitStream.Write(text);
bitStream.Write(target); // Who this message will be sent to on the (a) client
bitStream.Write(msgId); // the ID of this message

SEND_PACKET;
Serialize(bitStream); // write the message data

// Send to everyone if someone sent unassigned system address, or to one specific client.
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) {
SEND_PACKET_BROADCAST;
} else {
SEND_PACKET;
}
}

void DisplayTooltip::Serialize(RakNet::BitStream& bitStream) const {
bitStream.Write(doOrDie);
bitStream.Write(noRepeat);
bitStream.Write(noRevive);
bitStream.Write(isPropertyTooltip);
bitStream.Write(show);
bitStream.Write(translate);
bitStream.Write(time);
bitStream.Write<int32_t>(id.size());
bitStream.Write(id);

std::string toWrite;
for (const auto* item : localizeParams) {
toWrite += item->GetString() + "\n";
}
if (!toWrite.empty()) toWrite.pop_back();
bitStream.Write<int32_t>(toWrite.size());
bitStream.Write(GeneralUtils::ASCIIToUTF16(toWrite));
if (!toWrite.empty()) bitStream.Write<uint16_t>(0x00); // Null Terminator

bitStream.Write<int32_t>(imageName.size());
bitStream.Write(imageName);
bitStream.Write<int32_t>(text.size());
bitStream.Write(text);
}

void UseItemOnClient::Serialize(RakNet::BitStream& bitStream) const {
bitStream.Write(itemLOT);
bitStream.Write(itemToUse);
bitStream.Write(itemType);
bitStream.Write(playerId);
bitStream.Write(targetPosition.x);
bitStream.Write(targetPosition.y);
bitStream.Write(targetPosition.z);
}
}
16 changes: 13 additions & 3 deletions dGame/dGameMessages/GameMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ namespace GameMessages {
struct GameMsg {
GameMsg(MessageType::Game gmId) : msgId{ gmId } {}
virtual ~GameMsg() = default;
virtual void Send() const {}
void Send(const SystemAddress& sysAddr) const;
virtual void Serialize(RakNet::BitStream& bitStream) const {}
MessageType::Game msgId;
LWOOBJID target{ LWOOBJID_EMPTY };
SystemAddress sysAddr{ UNASSIGNED_SYSTEM_ADDRESS };
};

class PropertyDataMessage;
Expand Down Expand Up @@ -705,7 +705,17 @@ namespace GameMessages {
std::vector<LDFBaseData*> localizeParams{};
std::u16string imageName{};
std::u16string text{};
void Send() const override;
void Serialize(RakNet::BitStream& bitStream) const override;
};

struct UseItemOnClient : public GameMsg {
UseItemOnClient() : GameMsg(MessageType::Game::USE_ITEM_ON_CLIENT) {}
LWOOBJID playerId{};
LWOOBJID itemToUse{};
uint32_t itemType{};
LOT itemLOT{};
NiPoint3 targetPosition{};
void Serialize(RakNet::BitStream& bitStream) const override;
};
};

Expand Down
4 changes: 4 additions & 0 deletions dScripts/CppScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@
#include "WblRobotCitizen.h"
#include "EnemyClearThreat.h"
#include "AgSpiderBossMessage.h"
#include "GfRaceInstancer.h"

#include <map>
#include <string>
Expand Down Expand Up @@ -690,6 +691,7 @@ namespace {
{"scripts\\zone\\LUPs\\RobotCity Intro\\WBL_RCIntro_RobotCitizenYellow.lua", []() {return new WblRobotCitizen();}},
{"scripts\\02_server\\Map\\General\\L_ENEMY_CLEAR_THREAT.lua", []() {return new EnemyClearThreat();}},
{"scripts\\ai\\AG\\L_AG_SPIDER_BOSS_MESSAGE.lua", []() {return new AgSpiderBossMessage();}},
{"scripts\\ai\\GF\\L_GF_RACE_INSTANCER.lua", []() {return new GfRaceInstancer();}},

};

Expand All @@ -703,6 +705,8 @@ namespace {
"scripts\\zone\\AG\\L_ZONE_AG.lua",
"scripts\\zone\\NS\\L_ZONE_NS.lua",
"scripts\\zone\\GF\\L_ZONE_GF.lua",
"scripts\\ai\\AG\\CONCERT_STAGE.lua",
"scripts\\ai\\NS\\L_NS_CAR_MODULAR_BUILD.lua", // In our implementation, this is done in GameMessages.cpp
};
};

Expand Down
2 changes: 1 addition & 1 deletion dScripts/CppScripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ namespace CppScripts {
* @param player the player to remove
* @param canceled if it was done via the cancel button
*/
virtual void OnRequestActivityExit(Entity* sender, LWOOBJID player, bool canceled){};
virtual void OnRequestActivityExit(Entity* sender, LWOOBJID player, bool canceled) {};
};

Script* const GetScript(Entity* parent, const std::string& scriptName);
Expand Down
3 changes: 1 addition & 2 deletions dScripts/ai/AG/AgSpiderBossMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ void AgSpiderBossMessage::MakeBox(Entity* self) const {
if (!tgt) return;
GameMessages::DisplayTooltip tooltip;
tooltip.target = tgt->GetObjectID();
tooltip.sysAddr = tgt->GetSystemAddress();
tooltip.show = true;
tooltip.text = box.boxText;
tooltip.time = box.boxTime * 1000; // to ms
tooltip.Send();
tooltip.Send(tgt->GetSystemAddress());
}

void AgSpiderBossMessage::OnCollisionPhantom(Entity* self, Entity* target) {
Expand Down
1 change: 1 addition & 0 deletions dScripts/ai/GF/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(DSCRIPTS_SOURCES_AI_GF
"GfRaceInstancer.cpp"
"GfCampfire.cpp"
"GfOrgan.cpp"
"GfBanana.cpp"
Expand Down
7 changes: 7 additions & 0 deletions dScripts/ai/GF/GfRaceInstancer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "GfRaceInstancer.h"

#include "Entity.h"

void GfRaceInstancer::OnStartup(Entity* self) {
self->SetProximityRadius(self->HasVar(u"interaction_distance") ? self->GetVar<float>(u"interaction_distance") : 16.0f, "Interaction_Distance");
}
11 changes: 11 additions & 0 deletions dScripts/ai/GF/GfRaceInstancer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef GFRACEINSTANCER_H
#define GFRACEINSTANCER_H

#include "CppScripts.h"

class GfRaceInstancer : public CppScripts::Script {
public:
void OnStartup(Entity* self) override;
};

#endif //!GFRACEINSTANCER_H

0 comments on commit 15dc5fe

Please sign in to comment.