Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ammunition Related Work Items: #732 Related work items: #854
- Loading branch information
Allen B. Cummings
committed
Jan 19, 2021
1 parent
414a6e7
commit 2e8217d
Showing
6 changed files
with
301 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//***************************************************************************** | ||
// Copyright (c) 2021 - Allen Cummings, RealmsMUD, All rights reserved. See | ||
// the accompanying LICENSE file for details. | ||
//***************************************************************************** | ||
virtual inherit "/lib/items/ammunition.c"; | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
public void reset(int arg) | ||
{ | ||
if (!arg) | ||
{ | ||
set("name", "quiver"); | ||
set("short", "A quiver"); | ||
set("ammunition type", "arrow"); | ||
set("max capacity", 24); | ||
set("quantity", 24); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
//***************************************************************************** | ||
// Copyright (c) 2021 - Allen Cummings, RealmsMUD, All rights reserved. See | ||
// the accompanying LICENSE file for details. | ||
//***************************************************************************** | ||
virtual inherit "/lib/items/item.c"; | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
public nomask mixed query(string element) | ||
{ | ||
mixed ret = 0; | ||
switch(element) | ||
{ | ||
case "type": | ||
{ | ||
ret = "ammunition"; | ||
break; | ||
} | ||
case "remaining capacity": | ||
{ | ||
ret = itemData["max capacity"] - itemData["quantity"]; | ||
break; | ||
} | ||
case "short": | ||
{ | ||
ret = "item"::query("short"); | ||
if ((isIlluminated() > 8) && itemData["ammunition type"]) | ||
{ | ||
if (itemData["quantity"]) | ||
{ | ||
ret += sprintf(" containing %d %s%s (%d max)", | ||
itemData["quantity"], | ||
itemData["ammunition type"], | ||
(itemData["quantity"] == 1) ? "" : "s", | ||
itemData["max capacity"]); | ||
} | ||
else | ||
{ | ||
ret += sprintf(" that is empty (%d max)", | ||
itemData["max capacity"]); | ||
} | ||
} | ||
break; | ||
} | ||
case "low light description": | ||
{ | ||
ret = "The silhouette of a small, rectangular object"; | ||
break; | ||
} | ||
case "dim light description": | ||
{ | ||
ret = "Something that appears to be an ammunition container"; | ||
break; | ||
} | ||
default: | ||
{ | ||
ret = "item"::query(element); | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
public nomask int addAmmunition(int amount) | ||
{ | ||
int ret = 0; | ||
|
||
if (amount > 0) | ||
{ | ||
if (!member(itemData, "quantity")) | ||
{ | ||
itemData["quantity"] = 0; | ||
} | ||
|
||
int remainingCapacity = query("remaining capacity"); | ||
if (amount > remainingCapacity) | ||
{ | ||
itemData["quantity"] += remainingCapacity; | ||
ret = amount - remainingCapacity; | ||
} | ||
else | ||
{ | ||
itemData["quantity"] += amount; | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
public nomask varargs int set(string element, mixed data) | ||
{ | ||
int ret = 0; | ||
|
||
if (element && stringp(element)) | ||
{ | ||
switch (element) | ||
{ | ||
case "ammunition type": | ||
{ | ||
if (stringp(data)) | ||
{ | ||
ret = 1; | ||
itemData["ammunition type"] = data; | ||
} | ||
break; | ||
} | ||
case "max capacity": | ||
{ | ||
if (intp(data)) | ||
{ | ||
ret = 1; | ||
itemData["max capacity"] = data; | ||
} | ||
break; | ||
} | ||
case "quantity": | ||
{ | ||
if (intp(data) && member(itemData, "max capacity")) | ||
{ | ||
ret = 1; | ||
addAmmunition(data); | ||
} | ||
else | ||
{ | ||
raise_error("ammunition.c: 'max capacity' must be set before " | ||
"quantity"); | ||
} | ||
break; | ||
} | ||
default: | ||
{ | ||
ret = "item"::set(element, data); | ||
} | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
public nomask int doNotDestroyWhenConsumed() | ||
{ | ||
return 1; | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
public int id(string item) | ||
{ | ||
return (item == itemData["ammunition type"]) || | ||
"item"::id(item); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//***************************************************************************** | ||
// Copyright (c) 2021 - Allen Cummings, RealmsMUD, All rights reserved. See | ||
// the accompanying LICENSE file for details. | ||
//***************************************************************************** | ||
inherit "/lib/tests/framework/testFixture.c"; | ||
|
||
object Ammo; | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
void Setup() | ||
{ | ||
Ammo = clone_object("/lib/items/ammunition.c"); | ||
Ammo->set("name", "quiver"); | ||
Ammo->set("short", "A quiver"); | ||
Ammo->set("ammunition type", "arrow"); | ||
Ammo->set("max capacity", 24); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
void CleanUp() | ||
{ | ||
destruct(Ammo); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
void IdReturnsTrueForAmmunitionType() | ||
{ | ||
ExpectTrue(Ammo->id("arrow")); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
void ShortReturnsCorrectMessageWhenEmpty() | ||
{ | ||
ExpectEq("A quiver that is empty (24 max)", | ||
Ammo->short(), "short() returns correct value"); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
void ShortReturnsCorrectMessageWhenOneItemInContainer() | ||
{ | ||
Ammo->set("quantity", 1); | ||
|
||
ExpectEq("A quiver containing 1 arrow (24 max)", Ammo->short()); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
void AddAmmunitionAddsTheDesiredQuantityToTheContainer() | ||
{ | ||
Ammo->set("quantity", 1); | ||
|
||
ExpectEq(0, Ammo->addAmmunition(4)); | ||
ExpectEq("A quiver containing 5 arrows (24 max)", Ammo->short()); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
void AddingAmmunitionAboveCapacityReturnsLeftOverAmmo() | ||
{ | ||
Ammo->set("quantity", 10); | ||
|
||
ExpectEq(6, Ammo->addAmmunition(20)); | ||
ExpectEq("A quiver containing 24 arrows (24 max)", Ammo->short()); | ||
} |