📂
Bannerlord Modding CN
  • 骑马与砍杀2 领主 Mod 制作文档
  • C# API Documentation
    • Core
      • MBObjectManager
      • GameModel
      • InformationManager
      • BasicCharacterObject
      • Game
      • ItemObject
    • Campaign System
      • GameMenu
      • Settlement
      • CampaignGameStarter
      • actions
        • ChangeOwnerOfSettlementAction
      • TournamentGame
      • Hero : MBObjectBase, ITrackableCampaignObject, ITrackableBase
      • CampaignBehaviorBase
    • Mount And Blade
      • MissionBehaviour
        • MissionView
        • MissionLogic
      • MBInitialScreenBase
      • Mission
      • MBSubModuleBase
      • agent
      • Team
    • Input System
      • Input
    • Engine
      • GlobalLayer
      • ScriptComponentBehaviour
      • Scene
      • GameEntity
    • Library
      • ModuleInfo
    • Platform Service
    • Save System
    • Localization
      • MBTextManager
      • TextObject
    • Network
    • Two Dimension
  • XML Documentation
    • NPCCharacters
      • NPCCharacter(NPC角色)
        • upgrade_targets
          • upgrade_target
        • equipmentSet
          • equipment
        • Face
          • BodyProperties
          • hair_tags
            • hair_tag
          • BodyPropertiesMax
          • beard_tags
            • beard_tag
          • face_key_template
        • equipment
        • skills
          • skill
        • Traits
          • Trait
    • 物品(大类) Items
      • 物品 Item
        • 物品组件 ItemComponent
          • 马匹 Horse
            • Materials
              • Material
                • MeshMultipliers
                  • MeshMultiplier
          • 防具 Armor
          • Weapon
            • WeaponFlags
          • 食物 Food
        • 旗帜 Flags
      • CraftedItem
        • Pieces
          • Piece
    • Items (XML)
    • Scenes
      • Scene
        • GameType
        • TerrainType
          • TerrainType
    • SPCultures (XML)
    • SPCultures
      • Culture
        • female_names
          • name
        • male_names
          • name
        • clan_names
          • name
    • Atmosphere (XML)
    • SubModule (XML)
    • Scenes (XML)
    • NPCCharacters (XML)
  • Gauntlet
    • Brush
    • GauntletLayer
    • GauntletMovie
    • SceneLayer
    • Movie (XML)
    • Widget
    • GauntletView
    • ScreenBase
    • ViewModel
    • ScreenManager
  • Introduction
    • 高级用法
    • 开始第一步
    • 文件夹结构
    • Defining custom data
  • Tutorials
    • 将你的mod打包上传至Vortex
    • Making Banners
    • 不需要C#的UI系统Mod入门 #
    • 基本 C# Mod
    • new_settlements
  • ru
    • _intro
      • Начало
      • Структура папок
Powered by GitBook
On this page
  • Abstract Methods:
  • public abstract void RegisterEvents()
  • public abstract void SyncData(IDataStore dataStore)
  • Registering Campaign Behaviors:

Was this helpful?

  1. C# API Documentation
  2. Campaign System

CampaignBehaviorBase

PreviousHero : MBObjectBase, ITrackableCampaignObject, ITrackableBaseNextMount And Blade

Last updated 4 years ago

Was this helpful?

This is an abstract class within , and can be inherited to code for unique behaviours within the game's campaign.

Abstract Methods:

public abstract void RegisterEvents()

When defining this method, you can introduce consequences to certain events, by use of the CampaignEvents.On... methods. A simple example would be:

public override void RegisterEvents()
{   
    CampaignEvents.OnClanDestroyedEvent.AddNonSerializedListener(this, new Action<Clan>(
    clan => {
        String clanName = clan.Name.ToString();
        InformationManager.DisplayMessage(new InformationMessage("The " + clanName + " was destroyed!"));
    }));
}

The above example registers an event, such that when a clan is destroyed, a message is broadcasted to the chat. The AddNonSerializedListener method called here requires the second argument to be an action, which is described .

public abstract void SyncData(IDataStore dataStore)

Here you can manipulate data that your Behavior requires persist between saves. However, most Behavior won't need it and you can leave it empty if you wish.

If you do require it, the general form looks like this:

public override void SyncData(IDataStore dataStore)
{
    dataStore.SyncData(string_id_for_var, ref the_variable_itself);
}

For example, here is the storage of a counter of an event:

// inside your class
private int _numVillagesRaided;

public override void SyncData(IDataStore dataStore)
{
    dataStore.SyncData("_numVillagesRaided", ref _numVillagesRaided);
}

Perhaps you might increase this number every time the player raids a village, which will now persist between saves, and if they do it enough maybe give them something, like some gold or extra Roguery experience, or whatever you want.

The syntax is very simple, the first argument is a string identifier for what you are storing. This only needs to be unique within a given Behavior class, so you don't have to worry about having the same name as in someone else's Behavior. The second argument is a reference to the variable itself to save or load. You don't need to worry about which is happening, the game will handle it. If the player loads a save, it will write it to that variable, and if they save their game, it will read from it and into the save.

Registering Campaign Behaviors:

protected override void OnGameStart(Game game, IGameStarter gameStarter) 
{
    if(game.GameType is Campaign) 
    {
        //The current game is a campaign
        CampaignGameStarter campaignStarter = (CampaignGameStarter) gameStarter;
        campaignStarter.AddBehavior(new ExampleBehavior());
        //ExampleBehavoir is our custom class which extends CampaignBehaviorBase
    }
}

Within your class, you can utilise the OnGameStart Method to add the behavoir to a campaign. An example is given below:

TaleWorlds.CampaignSystem
here
MBSubModuleBase