protected override void InitInstance(object[] parameter) { items = container.Create <ItemList>(); entryCondition = container.Create <Condition>(); base.InitInstance(parameter); }
/// <summary> /// Set player to travel to destination. /// </summary> /// <param name="destination">destination location</param> public void Travel(Location destination) { SelectGroup(Group); RefreshScrollPosition = true; RefreshMapScrollPosition = true; foreach (Character chr in Group) { chr.Position = destination.EntryPoint; } for (int i = 0; i < Location.Neighbors.Count; i++) { if (Location.Neighbors[i] == destination) { remainingTravelDays = Location.WayLengths[i]; travelDays = remainingTravelDays; break; } } // set previous location previousLocation = this.Location; // set destination this.destination = destination; }
protected override void InitInstance(object[] parameter) { group = container.Create <Group>(); Group.RangeFilterValue = 50; refreshScrollPosition = true; refreshMapScrollPosition = true; index = (int)parameter[0]; }
protected override void InitInstance(object[] parameter) { items = container.Create <DroppedItemList>(); characters = container.CreateLinkList <Character>(); source = container.Create <WaterSource>(this); neighbors = container.CreateLinkList <Location>(); base.InitInstance(parameter); }
protected override void InitInstance(object[] parameter) { if (parameter.Length != 1) { throw new Burntime.Framework.BurntimeLogicException(); } location = parameter[0] as Location; }
// Use this for enter state public override void OnStateBegin() { StateLink link = GetRandomLink(); if (link != null) { Transition(link); } }
protected override void InitInstance(object[] parameter) { if (parameter == null || parameter.Length < 1 || !(parameter[0] is Character)) { throw new InvalidStateObjectConstruction(this); } owner = parameter[0] as Character; base.InitInstance(parameter); }
public virtual void OnCommand(EActionType action, byte[] param) { int id = (int)action; if (links.ContainsKey(id)) { StateLink link = links[id]; BaseState outstate = curFSM.FindChildState(link.linkStateName); Goto(outstate); } }
public void InitializeLinks(ItemTypes types) { if (data.Object.Empty != "") { empty = types[data.Object.Empty]; } if (data.Object.Full != "") { full = types[data.Object.Full]; } }
protected override void InitInstance(object[] parameter) { items = container.Create <ItemList>(); dialog = container.Create <Dialog>(); hireItems = container.CreateLinkList <ItemType>(); // set health to 1 to avoid IsDead getting true health = 1; AfterDeserialization(); base.InitInstance(parameter); }
protected override void InitInstance(object[] parameter) { if (parameter.Length != 3) { throw new Burntime.Framework.BurntimeLogicException(); } character = (Character)parameter[0]; remainingTime = (int)parameter[1]; this.location = (Location)parameter[2]; base.InitInstance(parameter); }
public bool SelectCharacter(Character targetCharacter) { if (SelectedCharacter == targetCharacter) { return(false); } // select single character selectedCharacter = targetCharacter; targetCharacter.Mind = container.Create <AI.PlayerControlledMind>(new object[] { targetCharacter }); singleMode = true; return(true); }
public void SelectGroup(ICharacterCollection targetGroup) { // for now assume the player's character is the leader selectedCharacter = Character; foreach (Character member in targetGroup) { if (member != Character) { member.Mind = container.Create <AI.FellowerMind>(new object[] { member, SelectedCharacter }); } } singleMode = targetGroup.Count == 1; }
public override BaseState Clone() { LogicEntityState cloneObj = new LogicEntityState(); cloneObj.durationTick = this.durationTick; cloneObj.name = this.name; foreach (KeyValuePair <int, StateLink> kv in m_links) { StateLink link = new StateLink(); link.linkID = kv.Value.linkID; link.linkStateName = kv.Value.linkStateName; cloneObj.m_links[link.linkID] = link; } return(cloneObj); }
public override void Turn() { Character.Path.MoveTo = Character.Position; RecalculateExperience(); if (remainingTravelDays > 0) { remainingTravelDays--; if (remainingTravelDays == 0) { Location = destination; destination = null; } } }
public override BaseState Clone() { EntityAnimationState cloneObj = new EntityAnimationState(); cloneObj.durationTick = this.durationTick; cloneObj.name = this.name; cloneObj.animantioName = this.animantioName; cloneObj.animationSpeed = this.animationSpeed; cloneObj.loopCount = this.loopCount; foreach (KeyValuePair <int, StateLink> kv in m_links) { StateLink link = new StateLink(); link.linkID = kv.Value.linkID; link.linkStateName = kv.Value.linkStateName; cloneObj.m_links[link.linkID] = link; } return(cloneObj); }
/// <summary> /// Turn mode - Look for next camp /// </summary> /// <returns>true if no further turn processing is needed</returns> private bool TurnModeLookForNextCamp() { if (MaxHumanCampCount + settings.MaxAdvance <= CampCount) { mode = Mode.None; return(false); } // if not at home, enemy camp or in a city and resources for a camp are available if (CanCreateCamp(CurrentLocation)) { // claim current camp Character npc = GetNpcForCamp(); if (npc != null) { JoinCamp(npc); } if (Player.Group.Count == 1) { // used group member to hire, find a new one mode = Mode.HireNpc; return(true); } else { // wait some time mode = Mode.WaitInterval; wait = Burntime.Platform.Math.Random.Next(settings.MinInterval, settings.MaxInterval); } } else { // find next possible camp location headedLocation = NearestFreeCamp(); if (headedLocation != null) { Player.Travel(headedLocation); } return(false); } return(false); }
private bool TurnModeHireNpc() { if (CanHireNpc()) { Character ch = HireNpc(); mode = Mode.LookForNextCamp; return(true); } else { headedLocation = NearestCity(); if (headedLocation != null) { Player.Travel(headedLocation); } } return(false); }
/// <summary> /// StateObject initialization /// </summary> /// <param name="parameter">Player, AiSettings</param> protected override void InitInstance(object[] parameter) { base.InitInstance(parameter); if (parameter.Length != 2) { throw new BurntimeLogicException(); } player = parameter[0] as Player; if (player == null) { throw new BurntimeLogicException(); } settings = (AiSettings)parameter[1]; mode = Mode.WaitInterval; wait = Burntime.Platform.Math.Random.Next(settings.MinInterval, settings.MaxInterval); itemPool = container.Create <AiItemPool>(); }
private void OnDestroy() { unloaded = null; }
protected override void InitInstance(object[] parameter) { this.type = parameter[0] as ItemType; count = 0; }
public void LoadFSMTemplate(XmlNode fsmNode) { Assembly assembly = Assembly.GetExecutingAssembly(); if (fsmNode == null || fsmNode.Name != "FSM") { return; } object fsmObj = assembly.CreateInstance(fsmNode.Attributes.GetNamedItem("type").Value); if (fsmObj != null) { BaseFSM bfsm = fsmObj as BaseFSM; bfsm.name = fsmNode.Attributes.GetNamedItem("name").Value; switch (bfsm.type) { case EFSM_TYPE.EFSM_DEFAULT_FSM: { } break; case EFSM_TYPE.EFSM_ENTITY_FSM: { } break; } //先将所有节点生成一遍,再设置连接关系 XmlNodeList stateNodes = fsmNode.ChildNodes; for (int i = 0; i < stateNodes.Count; i++) { XmlNode stateNode = stateNodes[i]; if (stateNode.Name != null && stateNode.Name == "StateNode") { //string t = typeof(EntityAnimationState).ToString(); //object stateObj = assembly.CreateInstance(t); object stateObj = assembly.CreateInstance(stateNode.Attributes.GetNamedItem("type").Value); if (stateObj != null) { BaseState state = stateObj as BaseState; state.name = stateNode.Attributes.GetNamedItem("name").Value; state.curFSM = bfsm; int duration = 0; int.TryParse(stateNode.Attributes.GetNamedItem("duration").Value, out duration); state.durationTick = duration; switch (state.type) { case EStateType.EStateType_LoginEntiy: { } break; case EStateType.EStateType_EntityAnimation: { EntityAnimationState animState = state as EntityAnimationState; animState.animantioName = stateNode.Attributes.GetNamedItem("AnimationType").Value; float speed = 0; float.TryParse(stateNode.Attributes.GetNamedItem("AnimationSpeed").Value, out speed); animState.animationSpeed = speed; int loopCount = 0; int.TryParse(stateNode.Attributes.GetNamedItem("loopCount").Value, out loopCount); animState.loopCount = loopCount; } break; } for (int j = 0; j < stateNode.ChildNodes.Count; j++) { XmlNode linkNode = stateNode.ChildNodes[j]; object linkObj = assembly.CreateInstance("StateLink"); if (linkObj != null) { StateLink link = linkObj as StateLink; object linkKey = Enum.Parse(typeof(EActionType), linkNode.Attributes.GetNamedItem("actionId").Value); if (linkKey != null) { link.linkID = (int)linkKey; link.linkStateName = linkNode.Attributes.GetNamedItem("linkStateName").Value; state.links.Add((int)linkKey, link); } } bfsm.AddStateNode(state); } } } } object defaultNode = bfsm.FindChildState(fsmNode.Attributes.GetNamedItem("defaultNode").Value); if (defaultNode != null) { bfsm.defaultNode = defaultNode as BaseState; } //设置连接关系 //foreach (XmlNode stateNode in fsmNode.ChildNodes) for (int i = 0; i < stateNodes.Count; i++) { XmlNode stateNode = stateNodes[i]; BaseState state = bfsm.FindChildState(stateNode.Attributes.GetNamedItem("name").Value); object outstate = bfsm.FindChildState(stateNode.Attributes.GetNamedItem("outState").Value); if (outstate != null) { state.timeOutState = outstate as BaseState; } } //添加到FSM表 m_fsmTemplates[bfsm.name] = bfsm; } }
public WaterGoal(Player player) { this.player = player; }
/// <summary> /// Item management, update pool, ... /// </summary> private void UpdateItems() { #warning after loading savegame this may be null, why? if (itemPool == null) { itemPool = container.Create <AiItemPool>(); } // add items from ground to item pool ItemPool.Insert(CurrentLocation.Items); // remove all items from ground CurrentLocation.Items.Clear(); int turn = Game.World.Day; // add weapons to pool (TODO make dependent on difficulty) if (turn % 3 == 0) { ItemPool.Insert(Game.ItemTypes["item_knife"]); } if (turn % 10 == 0) { ItemPool.Insert(Game.ItemTypes["item_axe"]); } if (turn % 15 == 0) { ItemPool.Insert(Game.ItemTypes["item_pitchfork"]); } if (turn % 20 == 0) { ItemPool.Insert(Game.ItemTypes["item_loaded_rifle"]); } if (turn % 17 == 0) { ItemPool.Insert(Game.ItemTypes["item_loaded_pistol"]); } // add traps to pool if (turn % 3 == 0) { ItemPool.Insert(Game.ItemTypes["item_knife"]); } if (turn % 7 == 0) { ItemPool.Insert(Game.ItemTypes["item_rat_trap"]); } if (turn % 11 == 0) { ItemPool.Insert(Game.ItemTypes["item_snake_trap"]); } if (turn % 14 == 0) { ItemPool.Insert(Game.ItemTypes["item_trap"]); } // add protection items to pool if (turn % 25 == 0) { ItemPool.Insert(Game.ItemTypes["item_gas_mask"]); } if (turn % 50 == 0) { ItemPool.Insert(Game.ItemTypes["item_protection_suit"]); } }
public virtual Conversation GetConversation(Character boss, ConversationType type) { lastDialog = this; // change conversation to talk if met the first time if (!talkedPlayer.Contains(boss.Player)) { talkedPlayer.Add(boss.Player); type = ConversationType.Talk; } switch (type) { case ConversationType.Dismiss: return(GetDismissConversation(boss)); case ConversationType.Abandon: return(GetAbandonConversation(boss)); case ConversationType.Capture: return(GetCaptureConversation(boss)); case ConversationType.Greeting: return(GetGreetingConversation(boss)); case ConversationType.Talk: return(GetTalkConversation(boss)); } int index = 0; Item hireItem = null; ItemType hireItemType = null; bool hire = false; if (type == ConversationType.Hire) { if (boss.Experience >= Parent.Experience * 0.66f) { for (int i = 0; hireItem == null && i < Parent.HireItems.Count; i++) { hireItem = boss.Items.Find(Parent.HireItems[i]); } if (null != hireItem) { hire = true; index = 4; hireItemType = hireItem.Type; } else { hireItemType = Parent.HireItems[0]; index = 5; } } else { index = 7; } } else if (type == ConversationType.Profession) { for (int i = 0; hireItem == null && i < Parent.HireItems.Count; i++) { hireItem = boss.Items.Find(Parent.HireItems[i]); } hire = true; index = 4; hireItemType = hireItem.Type; index = 6; } lastDialog = this; Conversation conv = new Conversation(); conv.Text = ResourceManager.GetStrings("men_" + MenFile.ToString("D3") + "?s" + index); conv.Choices = new ConversationChoice[3]; for (int i = 0; i < conv.Text.Length; i++) { conv.Text[i] = conv.Text[i].Replace("|A", ResourceManager.GetString("burn?431")); conv.Text[i] = conv.Text[i].Replace("|B", ResourceManager.GetString("burn?" + (40 + (int)Parent.Class))); if (hireItemType != null) { conv.Text[i] = conv.Text[i].Replace("|C", hireItemType.Text); } } conv.Choices[0] = new ConversationChoice(); conv.Choices[1] = new ConversationChoice(); if (Parent.Class == CharClass.Trader && boss.IsPlayerCharacter) { conv.Choices[0].Action = new ConversationAction(ConversationActionType.Trade); conv.Choices[0].Text = ResourceManager.GetString("burn?500"); conv.Choices[1].Action = new ConversationAction(ConversationActionType.Talk); conv.Choices[1].Text = ResourceManager.GetString("burn?492"); } else if (Parent.Class != CharClass.Mutant && Parent.Class != CharClass.Dog && boss.IsPlayerCharacter) { if (hire) { conv.Choices[0].Action = new ConversationAction(ConversationActionType.Profession); conv.Choices[0].Text = ResourceManager.GetString("burn?497"); conv.Choices[1].Action = new ConversationAction(ConversationActionType.Hire); conv.Choices[1].Text = ResourceManager.GetString("burn?498").Replace("|C", hireItemType.Text); } else { conv.Choices[0].Action = new ConversationAction(ConversationActionType.Talk); conv.Choices[0].Text = ResourceManager.GetString("burn?492"); conv.Choices[1].Action = new ConversationAction(ConversationActionType.HireRequirements); conv.Choices[1].Text = ResourceManager.GetString("burn?491"); } } else { conv.Choices[0].Action = new ConversationAction(ConversationActionType.None); conv.Choices[0].Text = ""; conv.Choices[1].Action = new ConversationAction(ConversationActionType.Talk); conv.Choices[1].Text = ResourceManager.GetString("burn?492"); } conv.Choices[2] = new ConversationChoice(); conv.Choices[2].Action = new ConversationAction(ConversationActionType.Exit); conv.Choices[2].Text = ResourceManager.GetString("burn?490"); return(conv); }