Skip to content

Commit

Permalink
Implement item: Potion of regeneration (#259)
Browse files Browse the repository at this point in the history
* Implement item effect on server side

* Implement Potion of Regeneration on client side

* simplify

* Add a few more methods

* add initialization

* Initialize in module

* Fix typing errors

* update

* update

* Update AnchorPoint

* Include inventory = {}

* Finalize item framework

* just a little bit more

* Use random item
  • Loading branch information
Christian-Toney authored Sep 12, 2024
1 parent e262ed8 commit 5e7ccce
Show file tree
Hide file tree
Showing 33 changed files with 453 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local Players = game:GetService("Players");
local ContextActionService = game:GetService("ContextActionService");
local ClientAction = require(script.Parent.Parent.ClientAction);
local React = require(ReplicatedStorage.Shared.Packages.react);
local ActionButton = require(script.Parent.Parent.Parent.ReactComponents.ActionButton);
local HUDButton = require(script.Parent.Parent.Parent.ReactComponents.HUDButton);
type ClientAction = ClientAction.ClientAction;

local TakeFlightAction = {
Expand Down Expand Up @@ -95,7 +95,9 @@ function TakeFlightAction.new(): ClientAction

end

ReplicatedStorage.Client.Functions.AddActionButton:Invoke(React.createElement(ActionButton, {
ReplicatedStorage.Client.Functions.AddHUDButton:Invoke("Action", React.createElement(HUDButton, {
type = "Action";
key = self.ID;
onActivate = function()

self:activate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local ContextActionService = game:GetService("ContextActionService");
local React = require(ReplicatedStorage.Shared.Packages.react);
local ReactRoblox = require(ReplicatedStorage.Shared.Packages["react-roblox"]);
local ClientAction = require(script.Parent.Parent.ClientAction);
local ActionButton = require(script.Parent.Parent.Parent.ReactComponents.ActionButton);
local HUDButton = require(script.Parent.Parent.Parent.ReactComponents.HUDButton);
local LimbSelectionWindow = require(script.Parent.Parent.Parent.ReactComponents.LimbSelectionWindow);
type ClientAction = ClientAction.ClientAction;

Expand Down Expand Up @@ -73,7 +73,9 @@ function DetachLimbAction.new(): ClientAction

end;

ReplicatedStorage.Client.Functions.AddActionButton:Invoke(React.createElement(ActionButton, {
ReplicatedStorage.Client.Functions.AddHUDButton:Invoke("Action", React.createElement(HUDButton, {
type = "Action";
key = self.ID;
onActivate = function() activateGUI() end;
shortcutCharacter = "L";
iconImage = "rbxassetid://17551046771";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local Players = game:GetService("Players");
-- local ContextActionService = game:GetService("ContextActionService");
local ClientAction = require(script.Parent.Parent.ClientAction);
local React = require(ReplicatedStorage.Shared.Packages.react);
local ActionButton = require(script.Parent.Parent.Parent.ReactComponents.ActionButton);
local HUDButton = require(script.Parent.Parent.Parent.ReactComponents.HUDButton);
type ClientAction = ClientAction.ClientAction;

local DetonateDetachedLimbsClientAction = {
Expand Down Expand Up @@ -34,10 +34,12 @@ function DetonateDetachedLimbsClientAction.new(): ClientAction

local function initialize(self: ClientAction)

ReplicatedStorage.Client.Functions.AddActionButton:Invoke(React.createElement(ActionButton, {
ReplicatedStorage.Client.Functions.AddHUDButton:Invoke("Action", React.createElement(HUDButton, {
type = "Action";
key = self.ID;
onActivate = function()

self:activate()
self:activate();

end;
shortcutCharacter = "L";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local Players = game:GetService("Players");
local ContextActionService = game:GetService("ContextActionService");
local ClientAction = require(script.Parent.Parent.ClientAction);
local React = require(ReplicatedStorage.Shared.Packages.react);
local ActionButton = require(script.Parent.Parent.Parent.ReactComponents.ActionButton);
local HUDButton = require(script.Parent.Parent.Parent.ReactComponents.HUDButton);
type ClientAction = ClientAction.ClientAction;

local ExplosivePunchAction = {
Expand All @@ -19,7 +19,6 @@ local ExplosivePunchAction = {
function ExplosivePunchAction.new(): ClientAction

local player = Players.LocalPlayer;
local remoteName: string;

local function breakdown(self: ClientAction)

Expand All @@ -29,13 +28,15 @@ function ExplosivePunchAction.new(): ClientAction

local function activate(self: ClientAction)

ReplicatedStorage.Shared.Functions.ActionFunctions:FindFirstChild(remoteName):InvokeServer();
ReplicatedStorage.Shared.Functions.ActionFunctions:FindFirstChild(`{player.UserId}_{self.ID}`):InvokeServer();

end;

local function initialize(self: ClientAction)

ReplicatedStorage.Client.Functions.AddActionButton:Invoke(React.createElement(ActionButton, {
ReplicatedStorage.Client.Functions.AddHUDButton:Invoke("Action", React.createElement(HUDButton, {
type = "Action";
key = self.ID;
onActivate = function()

self:activate();
Expand All @@ -44,8 +45,6 @@ function ExplosivePunchAction.new(): ClientAction
shortcutCharacter = "L";
iconImage = "rbxassetid://17771917538";
}));

remoteName = `{player.UserId}_{self.ID}`;

local function checkJump(_, inputState: Enum.UserInputState)

Expand Down
3 changes: 2 additions & 1 deletion src/ReplicatedStorage/Client/Classes/ClientItem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export type ClientItemProperties = {
name: string;
iconImage: string;
description: string;
activate: (self: ClientItem, ...any) -> ();
activate: (self: ClientItem) -> ();
breakdown: (self: ClientItem) -> ();
initialize: (self: ClientItem, ...any) -> ()
};

export type ClientItemEvents = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
-- Designer: InkyTheBlue (InkyTheBlue)
-- © 2024 Beastslash

local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Players = game:GetService("Players");
local ClientItem = require(script.Parent.Parent.ClientItem);
type ClientItem = ClientItem.ClientItem;
local React = require(ReplicatedStorage.Shared.Packages.react);
local HUDButton = require(ReplicatedStorage.Client.ReactComponents.HUDButton);

local PotionOfRegenerationClientItem = {
ID = 1;
Expand All @@ -16,12 +20,33 @@ local PotionOfRegenerationClientItem = {

function PotionOfRegenerationClientItem.new(): ClientItem

local _itemNumber: number?;

local function breakdown(self: ClientItem)

ReplicatedStorage.Client.Functions.DestroyHUDButton:Invoke("Item", `{self.ID}_{_itemNumber}`);

end;

local function activate(self: ClientItem)

assert(_itemNumber);
local player = Players.LocalPlayer;
ReplicatedStorage.Shared.Functions.ItemFunctions:FindFirstChild(`{player.UserId}_{self.ID}_{_itemNumber}`):InvokeServer();

end;

local function initialize(self: ClientItem, itemNumber: number)

local hudButton = React.createElement(HUDButton, {
type = "Item";
key = `{self.ID}_{itemNumber}`;
onActivate = function() self:activate() end;
iconImage = "rbxassetid://17551046771";
});
_itemNumber = itemNumber;
ReplicatedStorage.Client.Functions.AddHUDButton:Invoke("Item", hudButton);

end;

return ClientItem.new({
Expand All @@ -31,6 +56,7 @@ function PotionOfRegenerationClientItem.new(): ClientItem
description = PotionOfRegenerationClientItem.description;
breakdown = breakdown;
activate = activate;
initialize = initialize;
});

end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ function RocketLauncherClientItem.new(): ClientItem

end;

local function initialize(self: ClientItem)

end;

return ClientItem.new({
ID = RocketLauncherClientItem.ID;
iconImage = RocketLauncherClientItem.iconImage;
name = RocketLauncherClientItem.name;
description = RocketLauncherClientItem.description;
breakdown = breakdown;
activate = activate;
initialize = initialize;
});

end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ function SuperHammerClientItem.new(): ClientItem

end;

local function initialize(self: ClientItem)

end;

return ClientItem.new({
ID = SuperHammerClientItem.ID;
iconImage = SuperHammerClientItem.iconImage;
name = SuperHammerClientItem.name;
description = SuperHammerClientItem.description;
breakdown = breakdown;
activate = activate;
initialize = initialize;
});

end;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"className": "BindableFunction"
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ local UserInputService = game:GetService("UserInputService");
local useResponsiveDesign = require(ReplicatedStorage.Client.ReactHooks.useResponsiveDesign);
local CircleUICorner = require(script.Parent.CircleUICorner);

type LimbSelectionButtonProps = {
type HUDButtonProps = {
type: "Action" | "Item";
onActivate: () -> ();
shortcutCharacter: string;
iconImage: string?;
}

local function ActionButton(props: LimbSelectionButtonProps)
local function HUDButton(props: HUDButtonProps)

local isKeyboardEnabled, setIsKeyboardEnabled = React.useState(false);

Expand Down Expand Up @@ -47,7 +48,6 @@ local function ActionButton(props: LimbSelectionButtonProps)
});
IconContainerButton = React.createElement("TextButton", {
[React.Event.Activated] = onActivate;
Rotation = 45;
AnchorPoint = Vector2.new(0.5, 0.5);
BackgroundTransparency = 0.4;
BackgroundColor3 = Color3.new(0, 0, 0);
Expand All @@ -62,7 +62,7 @@ local function ActionButton(props: LimbSelectionButtonProps)
ApplyStrokeMode = Enum.ApplyStrokeMode.Border;
Transparency = 0.4;
});
UICorner = React.createElement(CircleUICorner);
UICorner = if props.type == "Action" then React.createElement(CircleUICorner) else nil;
IconImageLabel = if props.iconImage then React.createElement("ImageLabel", {
AnchorPoint = Vector2.new(0.5, 0.5);
Position = UDim2.new(0.5, 0, 0.5, 0);
Expand All @@ -84,4 +84,4 @@ local function ActionButton(props: LimbSelectionButtonProps)

end;

return ActionButton;
return HUDButton;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--!strict
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local React = require(ReplicatedStorage.Shared.Packages.react);

local function HUDButtonContainer(props)

local isActionList = props.type == "Action";

return React.createElement("Frame", {
AnchorPoint = Vector2.new(if isActionList then 1 else 0, 1);
Position = UDim2.new(if isActionList then 1 else 0, if isActionList then -15 else 15, 1, -15);
Size = UDim2.new();
AutomaticSize = Enum.AutomaticSize.XY;
BackgroundTransparency = 1;
}, {
UIListLayout = React.createElement("UIListLayout", {
Padding = UDim.new(0, 5);
FillDirection = Enum.FillDirection.Horizontal;
});
HUDButtonList = React.createElement(React.Fragment, {}, props.children);
});

end;

return HUDButtonContainer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"className": "RemoteFunction"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"className": "RemoteFunction"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"className": "Folder"
}
3 changes: 2 additions & 1 deletion src/ServerScriptService/MatchManagementScript.server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type ServerContestant = ServerContestant.ServerContestant;
local ServerArchetype = require(ServerStorage.Classes.ServerArchetype);
type ServerArchetype = ServerArchetype.ServerArchetype;
local Profile = require(ServerStorage.Classes.Profile);
local RunService = game:GetService("RunService");

-- Initialize the round.
local round;
Expand Down Expand Up @@ -105,6 +104,7 @@ local function startRound()
ID = i * 0.01;
character = character;
name = `NPC {i * 0.01}`;
inventory = {};
isBot = true;
isDisqualified = false;
teamID = if i > team1BotCount then 2 else 1;
Expand Down Expand Up @@ -399,6 +399,7 @@ local function checkPlayerList(player: Player)
player = player;
character = player.Character;
name = player.Name;
inventory = {};
profile = profile;
isBot = false;
isDisqualified = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ function DetachLimbServerAction.new(): ServerAction

if player == contestant.player then

action:activate(limbName);
self:activate(limbName);

else

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ function BatterUpDemonServerArchetype.new(): ServerArchetype
contestant = newContestant;
round = newRound;

if contestant.player then

ReplicatedStorage.Shared.Functions.InitializeArchetype:InvokeClient(contestant.player, self.ID);

end;

end;

return ServerArchetype.new({
Expand Down
Loading

0 comments on commit 5e7ccce

Please sign in to comment.