Skip to content

Instantly share code, notes, and snippets.

@blind-coder
Created April 28, 2015 08:44
Show Gist options
  • Save blind-coder/cca61c0e8e1cb778537a to your computer and use it in GitHub Desktop.
Save blind-coder/cca61c0e8e1cb778537a to your computer and use it in GitHub Desktop.
PZ inheritance mockup
Interpretation 1: Inherit specific item, modify it.
Implementation: probably easy
Impact on existing codebase: small to nonexistant.
Impact on future development: medium for mods changing existing items.
Advantages: changing only specific attributes of an item does not necessitate keeping all attributes in sync.
Disadvantages: unknown.
Example: Extending Bleach item:
Old:
module Base
{
item Bleach
{
UnhappyChange = 99,
UseDelta = 0.04,
Weight = 0.3,
Type = Drainable,
ThirstChange = -60,
DisplayName = Bleach,
Icon = Bleach,
Poison = true,
DisplayCategory = Item,
PoisonDetectionLevel = 7,
PoisonPower = 40,
UseForPoison = 15,
CustomContextMenu = Drink,
CustomEatSound = PZ_DrinkingFromBottle,
}
}
New:
module Base
{
item Bleach
{
inherit = Base.Bleach,
UseDelta = 0.04,
Weight = 0.3,
Type = Drainable
}
}
Interpretation 2: Do not add custom properties on child classes, but only set them as necessary.
Implementation: time-consuming
Impact on existing codebase: large, but compatibility can be maintained
Impact on future development: large for future mods
Advantages: no more limitations on properties based on Type
Disadvantages: might break existing items and mods if not implemented properly
Example: Mockup of newly implemented item class:
public class Item {
private boolean isEdible = false;
private boolean isCookable = false;
private boolean isCooked = false;
private boolean isDrainable = false;
private int hungerReduction = 0;
private int happinessReduction = 0;
private int useDelta = 0;
private int currentDelta = 0;
/* getters and setters as necessary */
/* initialiser(s) */
}
public class Food : Item {
public Food(){
setIsEdible(true);
setIsCookable(true);
setHungerReduction(20);
setHappinessReduction(10);
}
}
Mockup of turning Bleach into a Drainable with new class:
module Base
{
item Bleach
{
inherit = Base.Bleach,
UseDelta = 0.04, -- calls setUseDelta in Item class
}
}
Consequences in other code parts:
All occurences of "instanceof(Item, 'Food')" would be replaced with "Item:getIsEdible()" and so on.
This would make it possible to have more possible combinations of properties that are not possible with the current classes (having DrainableComboItem properties on Food items, or vice-versa).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment