clean up example mod

This commit is contained in:
Ell 2022-03-21 18:56:23 +01:00
parent 7767cd7f18
commit f19ae32543
3 changed files with 13 additions and 10 deletions

View file

@ -21,12 +21,12 @@ public class CustomTable : Furniture {
public override void OnAdded() { public override void OnAdded() {
base.OnAdded(); base.OnAdded();
ExampleMod.Logger.Info("We were added at " + this.Position); ExampleMod.Logger.Info("The custom table was added at " + this.Position);
} }
public override void OnRemoved() { public override void OnRemoved() {
base.OnRemoved(); base.OnRemoved();
ExampleMod.Logger.Info("We were removed from " + this.Position); ExampleMod.Logger.Info("The custom table was removed from " + this.Position);
} }
// validate is called when this object is loaded from disk // validate is called when this object is loaded from disk

View file

@ -36,7 +36,7 @@ public class ExampleMod : Mod {
// adding a custom furniture item // adding a custom furniture item
FurnitureType.Register(new FurnitureType.TypeSettings("ExampleMod.CustomTable", new Point(1, 1), ObjectCategory.Table, 150, ColorScheme.SimpleWood) { FurnitureType.Register(new FurnitureType.TypeSettings("ExampleMod.CustomTable", new Point(1, 1), ObjectCategory.Table, 150, ColorScheme.SimpleWood) {
// specify the type that should be constructed when this furniture type is placed // specify the type that should be constructed when this furniture type is placed
// if this is not specified, the Furniture class is used, which is used for furniture without special animations or data // if this is not specified, the Furniture class is used, which is used for furniture without special animations or data
ConstructedType = typeof(CustomTable), ConstructedType = typeof(CustomTable),
// specifying icons for custom clothes and furniture is optional, but using the mod's icon helps users recognize a mod's features // specifying icons for custom clothes and furniture is optional, but using the mod's icon helps users recognize a mod's features
Icon = this.Icon, Icon = this.Icon,
@ -70,18 +70,17 @@ public class ExampleMod : Mod {
// adding a simple action: sitting down in the grass, which also gives us a nice emotion modifier // adding a simple action: sitting down in the grass, which also gives us a nice emotion modifier
ActionType.Register(new ActionType.TypeSettings("ExampleMod.SitOnGrass", ObjectCategory.Ground, typeof(SitDownOnGrassAction)) { ActionType.Register(new ActionType.TypeSettings("ExampleMod.SitOnGrass", ObjectCategory.Ground, typeof(SitDownOnGrassAction)) {
// we set this action to be executable only on grass tiles, not on other ground // we set this action to be executable only on grass tiles, not on other ground
CanExecute = (info, automatic) => { CanExecute = (actionInfo, automatic) => {
if (!info.Map.IsInBounds(info.ActionLocation.ToPoint())) if (!actionInfo.Map.IsInBounds(actionInfo.ActionLocation.ToPoint()))
return ActionType.CanExecuteResult.Hidden; return ActionType.CanExecuteResult.Hidden;
var tile = info.Map.GetTile(info.ActionLocation.ToPoint()); var tile = actionInfo.Map.GetTile(actionInfo.ActionLocation.ToPoint());
if (tile.Name.StartsWith("Grass")) // hidden means the action won't be displayed in the ring menu, Valid means the player (or AI) is able to enqueue and execute it
return ActionType.CanExecuteResult.Valid; return tile.Name.StartsWith("Grass") ? ActionType.CanExecuteResult.Valid : ActionType.CanExecuteResult.Hidden;
// hidden means the action won't be displayed in the ring menu
return ActionType.CanExecuteResult.Hidden;
}, },
Ai = { Ai = {
// we allow the action to be done even if the solved needs aren't low enough on a person // we allow the action to be done even if the solved needs aren't low enough on a person
CanDoRandomly = true, CanDoRandomly = true,
// the solved needs indicate when the AI should mark this action as important, they don't actually have to match the action's behavior
SolvedNeeds = new[] {NeedType.Energy}, SolvedNeeds = new[] {NeedType.Energy},
// make people more likely to sit down in the grass if they're uncomfortable // make people more likely to sit down in the grass if they're uncomfortable
PassivePriority = p => p.Emotion == EmotionType.Uncomfortable ? 150 : 25 PassivePriority = p => p.Emotion == EmotionType.Uncomfortable ? 150 : 25
@ -89,6 +88,8 @@ public class ExampleMod : Mod {
// since this action doesn't use objects (like chairs etc.), we set a texture to display instead // since this action doesn't use objects (like chairs etc.), we set a texture to display instead
Texture = this.uiTextures[1, 0] Texture = this.uiTextures[1, 0]
}); });
// we use this emotion modifier in SitDownOnGrassAction
GrassSittingModifier = EmotionModifier.Register( GrassSittingModifier = EmotionModifier.Register(
new EmotionModifier("ExampleMod.GrassSitting", this.uiTextures[1, 0], EmotionType.Happy)); new EmotionModifier("ExampleMod.GrassSitting", this.uiTextures[1, 0], EmotionType.Happy));
} }

View file

@ -18,6 +18,8 @@ public class SitDownOnGrassAction : MultiAction {
protected override IEnumerable<Action> CreateFirstActions() { protected override IEnumerable<Action> CreateFirstActions() {
// we want to walk to the location clicked, so we use the current action info // we want to walk to the location clicked, so we use the current action info
yield return ActionType.GoHere.Construct(this.Info); yield return ActionType.GoHere.Construct(this.Info);
// if multiple things should be done before starting this action, they can all be returned here
} }
protected override void AndThenInitialize() { protected override void AndThenInitialize() {