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() {
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() {
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

View file

@ -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
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
CanExecute = (info, automatic) => {
if (!info.Map.IsInBounds(info.ActionLocation.ToPoint()))
return ActionType.CanExecuteResult.Hidden;
var tile = info.Map.GetTile(info.ActionLocation.ToPoint());
if (tile.Name.StartsWith("Grass"))
return ActionType.CanExecuteResult.Valid;
// hidden means the action won't be displayed in the ring menu
CanExecute = (actionInfo, automatic) => {
if (!actionInfo.Map.IsInBounds(actionInfo.ActionLocation.ToPoint()))
return ActionType.CanExecuteResult.Hidden;
var tile = actionInfo.Map.GetTile(actionInfo.ActionLocation.ToPoint());
// 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 tile.Name.StartsWith("Grass") ? ActionType.CanExecuteResult.Valid : ActionType.CanExecuteResult.Hidden;
},
Ai = {
// we allow the action to be done even if the solved needs aren't low enough on a person
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},
// make people more likely to sit down in the grass if they're uncomfortable
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
Texture = this.uiTextures[1, 0]
});
// we use this emotion modifier in SitDownOnGrassAction
GrassSittingModifier = EmotionModifier.Register(
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() {
// we want to walk to the location clicked, so we use the current action 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() {