Skip to content

Commit

Permalink
LS: Add item for buying doors
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed May 29, 2023
1 parent 0835340 commit 2c2c7d3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
23 changes: 14 additions & 9 deletions MCGalaxy/Commands/CPE/CmdHold.cs
Expand Up @@ -30,17 +30,22 @@ public sealed class CmdHold : Command2

public override void Use(Player p, string message, CommandData data) {
if (message.Length == 0) { Help(p); return; }
string[] args = message.SplitSpaces(3);
string[] args = message.SplitSpaces(2);

CpeMessageType type = 0;
if (!CommandParser.GetEnum(p, args[0], "Type", ref type)) return;
BlockID block;
if (!CommandParser.GetBlock(p, args[0], out block)) return;
bool locked = false;
if (args.Length > 1 && !CommandParser.GetBool(p, args[1], ref locked)) return;

PersistentMessagePriority pri = 0;
if (!CommandParser.GetEnum(p, args[1], "PRI", ref pri)) return;
if (Block.IsPhysicsType(block)) {
p.Message("Cannot hold physics blocks"); return;
}

string msg = args.Length > 2 ? args[2] : "";
p.SendCpeMessage(type, msg, pri);
p.Message("----");
if (p.Session.SendHoldThis(block, locked)) {
p.Message("Set your held block to {0}.", Block.GetName(p, block));
} else {
p.Message("Your client doesn't support changing your held block.");
}
}

public override void Help(Player p) {
Expand All @@ -49,4 +54,4 @@ public sealed class CmdHold : Command2
p.Message("&H <locked> optionally prevents you from changing it");
}
}
}
}
3 changes: 3 additions & 0 deletions MCGalaxy/Modules/Games/LavaSurvival/LSGame.DB.cs
Expand Up @@ -29,17 +29,20 @@ public sealed partial class LSGame : RoundsGame
Economy.RegisterItem(itemLife);
Economy.RegisterItem(itemSponges);
Economy.RegisterItem(itemWater);
Economy.RegisterItem(itemDoors);
}

static void UnhookItems() {
Economy.Items.Remove(itemLife);
Economy.Items.Remove(itemSponges);
Economy.Items.Remove(itemWater);
Economy.Items.Remove(itemDoors);
}

static Item itemLife = new LifeItem();
static Item itemSponges = new SpongesItem();
static Item itemWater = new WaterItem();
static Item itemDoors = new DoorsItem();


static void HookCommands() {
Expand Down
11 changes: 11 additions & 0 deletions MCGalaxy/Modules/Games/LavaSurvival/LSGame.Physics.cs
Expand Up @@ -31,6 +31,7 @@ public sealed partial class LSGame : RoundsGame
Map.UpdateBlockHandlers(Block.Deadly_ActiveWater);
Map.UpdateBlockHandlers(Block.Lava);
Map.UpdateBlockHandlers(Block.Deadly_ActiveLava);
Map.UpdateBlockHandlers(Block.Door_Log);
}

void HandleBlockHandlersUpdated(Level lvl, BlockID block) {
Expand All @@ -49,6 +50,8 @@ public sealed partial class LSGame : RoundsGame
case Block.Lava:
case Block.Deadly_ActiveLava:
lvl.PhysicsHandlers[block] = DoLava; break;
case Block.Door_Log:
lvl.PlaceHandlers[block] = PlaceDoor; break;
}
}

Expand All @@ -71,6 +74,14 @@ public sealed partial class LSGame : RoundsGame
return ChangeResult.Modified;
}

ChangeResult PlaceDoor(Player p, BlockID newBlock, ushort x, ushort y, ushort z) {
LSData data = Get(p);
bool placed = TryPlaceBlock(p, ref data.DoorsLeft, "Door blocks", Block.Door_Log, x, y, z);
if (!placed) return ChangeResult.Unchanged;

return ChangeResult.Modified;
}


void DoSponge(Level lvl, ref PhysInfo C) {
if (C.Data.Value2++ < Config.SpongeLife) return;
Expand Down
3 changes: 2 additions & 1 deletion MCGalaxy/Modules/Games/LavaSurvival/LSGame.cs
Expand Up @@ -25,7 +25,7 @@ namespace MCGalaxy.Modules.Games.LS
{
public sealed class LSData
{
public int TimesDied, SpongesLeft, WaterLeft;
public int TimesDied, SpongesLeft, WaterLeft, DoorsLeft;
}

public enum LSFloodMode
Expand Down Expand Up @@ -166,6 +166,7 @@ public sealed partial class LSGame : RoundsGame
static void ResetRoundState(Player p, LSData data) {
data.SpongesLeft = 10;
data.WaterLeft = 30;
data.DoorsLeft = 0;
}


Expand Down
25 changes: 25 additions & 0 deletions MCGalaxy/Modules/Games/LavaSurvival/LSItems.cs
Expand Up @@ -93,4 +93,29 @@ sealed class WaterItem : SimpleItem
Economy.MakePurchase(p, Price, "%3Water:");
}
}

sealed class DoorsItem : SimpleItem
{
public DoorsItem() {
Aliases = new string[] { "door", "doors" };
Enabled = true;
Price = 2;
}

public override string Name { get { return "Door"; } }

public override void OnPurchase(Player p, string args) {
if (!LSGame.Instance.RoundInProgress) {
p.Message("You can only buy doors " +
"when a round of lava survival is in progress."); return;
}
if (!CheckPrice(p)) return;

// TODO avoid code duplication
LSData data = LSGame.Get(p);
data.DoorsLeft += 6;
p.Message("Door blocks left: &4{0}", data.DoorsLeft);
Economy.MakePurchase(p, Price, "%3Doors:");
}
}
}

0 comments on commit 2c2c7d3

Please sign in to comment.