Skip to content

Commit

Permalink
[fixed] major issues caused by kag update
Browse files Browse the repository at this point in the history
  • Loading branch information
Gingerbeard5773 committed May 5, 2024
1 parent afd50b3 commit 8df9f47
Show file tree
Hide file tree
Showing 41 changed files with 2,749 additions and 1,906 deletions.
244 changes: 124 additions & 120 deletions Entities/Characters/Builder/BuilderInventory.as
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@

namespace Builder
{
enum Cmd
{
nil = 0,
TOOL_CLEAR = 31,
PAGE_SELECT = 32,

make_block = 64,
make_reserved = 99
};

enum Page
{
PAGE_ZERO = 0,
PAGE_ONE,
//PAGE_TWO,
//PAGE_THREE,
PAGE_COUNT
};
}
Expand All @@ -45,8 +37,6 @@ const u8 GRID_PADDING = 12;

const u32 SHOW_NO_BUILD_TIME = 90;

const bool QUICK_SWAP_ENABLED = false;

void onInit(CInventory@ this)
{
CBlob@ blob = this.getBlob();
Expand All @@ -71,19 +61,20 @@ void onInit(CInventory@ this)
AddIconToken("$"+PAGE_NAME[i]+"$", "BuilderPageIcons.png", Vec2f(48, 24), i);
}

blob.addCommandID("make block");
blob.addCommandID("make block client");
blob.addCommandID("tool clear");
blob.addCommandID("tool clear client");
blob.addCommandID("page select");
blob.addCommandID("page select client");

blob.set_Vec2f("backpack position", Vec2f_zero);

blob.set_u8("build page", 0);

blob.set_u8("buildblob", 255);
blob.set_TileType("buildtile", 0);

if (QUICK_SWAP_ENABLED)
{
blob.set_u8("current block", 255); // 255 for no block
blob.set_u8("prev block", 255);
}

blob.set_u32("cant build time", 0);
blob.set_u32("show build time", 0);

Expand All @@ -98,10 +89,9 @@ void MakeBlocksMenu(CInventory@ this, const Vec2f &in INVENTORY_CE)
BuildBlock[][]@ blocks;
blob.get(blocks_property, @blocks);
if (blocks is null) return;

const u8 PAGE = blob.get_u8("build page");
const Vec2f MENU_SIZE = PAGE_SIZE[PAGE];

const Vec2f MENU_CE = Vec2f(0, MENU_SIZE.y * -GRID_SIZE - GRID_PADDING) + INVENTORY_CE;

CGridMenu@ menu = CreateGridMenu(MENU_CE, blob, MENU_SIZE, getTranslatedString("Build"));
Expand All @@ -114,7 +104,9 @@ void MakeBlocksMenu(CInventory@ this, const Vec2f &in INVENTORY_CE)
BuildBlock@ b = blocks[PAGE][i];
if (b is null) continue;
string block_desc = getTranslatedString(b.description);
CGridButton@ button = menu.AddButton(b.icon, "\n" + block_desc, Builder::make_block + i);
CBitStream params;
params.write_u8(i);
CGridButton@ button = menu.AddButton(b.icon, "\n" + block_desc, blob.getCommandID("make block"), params);
if (button is null) continue;

button.selectOneOnClick = true;
Expand Down Expand Up @@ -148,10 +140,7 @@ void MakeBlocksMenu(CInventory@ this, const Vec2f &in INVENTORY_CE)
{
tool.SetCaptionEnabled(false);

CBitStream params;
params.write_u16(blob.getNetworkID());

CGridButton@ clear = tool.AddButton("$BUILDER_CLEAR$", "", Builder::TOOL_CLEAR, Vec2f(1, 1), params);
CGridButton@ clear = tool.AddButton("$BUILDER_CLEAR$", "", blob.getCommandID("tool clear"), Vec2f(1, 1));
if (clear !is null)
{
clear.SetHoverText(getTranslatedString("Stop building\n"));
Expand All @@ -168,12 +157,12 @@ void MakeBlocksMenu(CInventory@ this, const Vec2f &in INVENTORY_CE)
{
index.deleteAfterClick = false;

CBitStream params;
params.write_u16(blob.getNetworkID());

for(u8 i = 0; i < Builder::PAGE_COUNT; i++)
{
CGridButton@ button = index.AddButton("$"+PAGE_NAME[i]+"$", PAGE_NAME[i], Builder::PAGE_SELECT + i, Vec2f(2, 1), params);
CBitStream params;
params.write_u8(i);
CGridButton@ button = index.AddButton("$"+PAGE_NAME[i]+"$", PAGE_NAME[i], blob.getCommandID("page select"), Vec2f(2, 1), params);
if (button is null) continue;

button.selectOneOnClick = true;
Expand Down Expand Up @@ -202,19 +191,26 @@ void onCreateInventoryMenu(CInventory@ this, CBlob@ forBlob, CGridMenu@ menu)

void onCommand(CInventory@ this, u8 cmd, CBitStream@ params)
{
string dbg = "BuilderInventory.as: Unknown command ";

CBlob@ blob = this.getBlob();
if (blob is null) return;

if (cmd >= Builder::make_block && cmd < Builder::make_reserved)
if (cmd == blob.getCommandID("make block") && isServer())
{
const bool isServer = getNet().isServer();
CPlayer@ callerp = getNet().getActiveCommandPlayer();
if (callerp is null) return;

CBlob@ callerb = callerp.getBlob();
if (callerb is null) return;
if (callerb !is blob) return;
BuildBlock[][]@ blocks;
if (!blob.get(blocks_property, @blocks)) return;

uint i = cmd - Builder::make_block;
u8 i;
if (!params.saferead_u8(i)) return;

CBitStream sparams;
sparams.write_u8(i);
blob.SendCommand(blob.getCommandID("make block client"), sparams);

const u8 PAGE = blob.get_u8("build page");
if (blocks !is null && i >= 0 && i < blocks[PAGE].length)
Expand All @@ -223,39 +219,30 @@ void onCommand(CInventory@ this, u8 cmd, CBitStream@ params)
bool canBuildBlock = canBuild(blob, @blocks[PAGE], i) && !isKnocked(blob);
if (!canBuildBlock)
{
if (blob.isMyPlayer())
{
blob.getSprite().PlaySound("/NoAmmo", 0.5);
}

return;
}

// put carried in inventory thing first
if (isServer)
CBlob@ carryBlob = blob.getCarriedBlob();
if (carryBlob !is null)
{
CBlob@ carryBlob = blob.getCarriedBlob();
if (carryBlob !is null)
// check if this isn't what we wanted to create
if (carryBlob.getName() == block.name)
{
// check if this isn't what we wanted to create
if (carryBlob.getName() == block.name)
{
return;
}
return;
}

if (carryBlob.hasTag("temp blob"))
{
carryBlob.Untag("temp blob");
carryBlob.server_Die();
}
else
if (carryBlob.hasTag("temp blob"))
{
carryBlob.Untag("temp blob");
carryBlob.server_Die();
}
else
{
// try put into inventory whatever was in hands
// creates infinite mats duplicating if used on build block, not great :/
if (!block.buildOnGround && !blob.server_PutInInventory(carryBlob))
{
// try put into inventory whatever was in hands
// creates infinite mats duplicating if used on build block, not great :/
if (!block.buildOnGround && !blob.server_PutInInventory(carryBlob))
{
carryBlob.server_DetachFromAll();
}
carryBlob.server_DetachFromAll();
}
}
}
Expand All @@ -268,90 +255,106 @@ void onCommand(CInventory@ this, u8 cmd, CBitStream@ params)
{
blob.set_TileType("buildtile", block.tile);
}
}
}
else if (cmd == blob.getCommandID("make block client") && isClient())
{
BuildBlock[][]@ blocks;
if (!blob.get(blocks_property, @blocks)) return;

if (blob.isMyPlayer())
{
SetHelp(blob, "help self action", "builder", getTranslatedString("$Build$Build/Place $LMB$"), "", 3);
}
u8 i;
if (!params.saferead_u8(i)) return;

if (QUICK_SWAP_ENABLED && blob.get_u8("current block") != i)
const u8 PAGE = blob.get_u8("build page");
if (blocks !is null && i >= 0 && i < blocks[PAGE].length)
{
BuildBlock@ block = @blocks[PAGE][i];
bool canBuildBlock = canBuild(blob, @blocks[PAGE], i) && !isKnocked(blob);
if (!canBuildBlock)
{
if (block.name == "building")
{
u8 temp = blob.get_u8("current block");
blob.set_u8("current block", blob.get_u8("prev block"));
blob.set_u8("prev block", temp);
}
else
if (blob.isMyPlayer())
{
blob.set_u8("prev block", blob.get_u8("current block"));
blob.set_u8("current block", i);
blob.getSprite().PlaySound("/NoAmmo", 0.5);
}
return;
}

if (block.tile == 0)
{
server_BuildBlob(blob, @blocks[PAGE], i);
}
else
{
blob.set_TileType("buildtile", block.tile);
}

if (blob.isMyPlayer())
{
SetHelp(blob, "help self action", "builder", getTranslatedString("$Build$Build/Place $LMB$"), "", 3);
}
}
}
else if (cmd == Builder::TOOL_CLEAR)
else if (cmd == blob.getCommandID("tool clear") && isServer())
{
u16 id;
if (!params.saferead_u16(id)) return;
CPlayer@ callerp = getNet().getActiveCommandPlayer();
if (callerp is null) return;

CBlob@ target = getBlobByNetworkID(id);
if (target is null) return;
CBlob@ callerb = callerp.getBlob();
if (callerb is null) return;
if (callerb !is blob) return;

target.ClearGridMenus();
ClearCarriedBlock(blob);

ClearCarriedBlock(target);

if (QUICK_SWAP_ENABLED && blob.get_u8("current block") != 255)
{
blob.set_u8("prev block", blob.get_u8("current block"));
blob.set_u8("current block", 255);
}
blob.server_SendCommandToPlayer(blob.getCommandID("tool clear client"), callerp);
}
else if (cmd >= Builder::PAGE_SELECT && cmd < Builder::PAGE_SELECT + Builder::PAGE_COUNT)
else if (cmd == blob.getCommandID("tool clear client") && isClient())
{
u16 id;
if (!params.saferead_u16(id)) return;
blob.ClearGridMenus();

CBlob@ target = getBlobByNetworkID(id);
if (target is null) return;

target.ClearGridMenus();
ClearCarriedBlock(blob);
}
else if (cmd == blob.getCommandID("page select") && isServer())
{
CPlayer@ callerp = getNet().getActiveCommandPlayer();
if (callerp is null) return;

if (QUICK_SWAP_ENABLED && blob.get_u8("build page") != cmd - Builder::PAGE_SELECT)
{
blob.set_u8("prev block", 255);
blob.set_u8("current block", 255);
}
CBlob@ callerb = callerp.getBlob();
if (callerb is null) return;
if (callerb !is blob) return;

target.set_u8("build page", cmd - Builder::PAGE_SELECT);
u8 page;
if (!params.saferead_u8(page)) return;

ClearCarriedBlock(target);
blob.set_u8("build page", page);

if (target is getLocalPlayerBlob())
{
target.CreateInventoryMenu(target.get_Vec2f("backpack position"));
}
}
else if (cmd == blob.getCommandID("cycle") && QUICK_SWAP_ENABLED)
{
if (isServer()) //only send once - server will have lowest ping for this
ClearCarriedBlock(blob);

if (isClient()) //localhost
{
if (blob.get_u8("prev block") == 255)
blob.ClearGridMenus();
if (blob is getLocalPlayerBlob())
{
CBitStream params;
params.write_u16(blob.getNetworkID());
blob.SendCommand(Builder::TOOL_CLEAR, params);
}
else
{
blob.SendCommand(Builder::make_block + blob.get_u8("prev block"));
blob.CreateInventoryMenu(blob.get_Vec2f("backpack position"));
}
}

if (blob.isMyPlayer())
CBitStream sparams;
sparams.write_u8(page);
blob.server_SendCommandToPlayer(blob.getCommandID("page select client"), sparams, callerp);
}
else if (cmd == blob.getCommandID("page select client") && isClient())
{
u8 page;
if (!params.saferead_u8(page)) return;

blob.ClearGridMenus();
blob.set_u8("build page", page);

ClearCarriedBlock(blob);

if (blob is getLocalPlayerBlob())
{
Sound::Play("/CycleInventory.ogg");
blob.CreateInventoryMenu(blob.get_Vec2f("backpack position"));
}
}
}
Expand Down Expand Up @@ -391,10 +394,11 @@ void onTick(CBlob@ this)
{
if (controls.isKeyJustPressed(KEY_KEY_1 + i))
{
this.SendCommand(Builder::make_block + blockBinds[i]);
CBitStream params;
params.write_u8(blockBinds[i]);
this.SendCommand(this.getCommandID("make block"), params);
}
}

}
}

Expand Down
6 changes: 3 additions & 3 deletions Entities/Characters/Scripts/RunnerDeath.as
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ f32 onHit(CBlob@ this, Vec2f worldPoint, Vec2f velocity, f32 damage, CBlob@ hitt
if (attach !is null)
{
CBlob@ held = attach.getOccupied();
if (held !is null && held.hasCommandID("revive"))
if (held !is null && held.hasCommandID("server_revive"))
{
if (isServer())
if (this.isMyPlayer())
{
CBitStream params;
params.write_netid(this.getNetworkID());
params.write_bool(true);
held.SendCommand(held.getCommandID("revive"), params);
held.SendCommand(held.getCommandID("server_revive"), params);
}

return 0.0f;
Expand Down
Loading

0 comments on commit 8df9f47

Please sign in to comment.