public override StateOperationResult OnSelectPosition(FDPosition position) { if (this.magicRange == null) { // should not happen return(StateOperationResult.Clear()); } if (this.magicRange.Contains(position)) { DirectRangeFinder rangeFinder = new DirectRangeFinder(gameAction.GetField(), position, this.Magic.EffectScope); FDRange magicScope = rangeFinder.CalculateRange(); List <FDCreature> targets = gameAction.GetCreatureInRange(magicScope, CreatureFaction.Enemy); if (targets == null || targets.Count == 0) { // Cannot spell on that position, do nothing return(StateOperationResult.None()); } else { gameAction.DoCreatureSpellMagic(this.Creature.CreatureId, this.Magic.MagicId, position); return(StateOperationResult.Clear()); } } else { // Cancel the magic return(StateOperationResult.Pop()); } }
private StateOperationResult OnMagicSelected(int index) { Debug.Log("MenuActionState: OnMagicSelected."); if (index < 0 || index >= this.Creature.Data.Magics.Count) { // Cancelled return(StateOperationResult.Pop()); } int magicId = this.Creature.Data.Magics[index]; MagicDefinition magicDefinition = DefinitionStore.Instance.GetMagicDefinition(magicId); if (magicDefinition != null && this.Creature.Data.CanSpellMagic() && magicDefinition.MpCost <= this.Creature.Data.Mp) { // Enough MP to spell SelecteMagicTargetState magicTargetState = new SelecteMagicTargetState(gameAction, this.Creature, magicDefinition); return(StateOperationResult.Push(magicTargetState)); } else { // Go back to open magic info CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectMagic); SendPack(pack); return(StateOperationResult.None()); } }
public override StateOperationResult OnSelectPosition(FDPosition position) { if (range == null || !range.Contains(position)) { return(StateOperationResult.Pop()); } // No creature or not a friend/NPC FDCreature targetCreature = this.gameAction.GetCreatureAt(position); if (targetCreature == null || targetCreature.Faction == Definitions.CreatureFaction.Enemy) { return(StateOperationResult.None()); } if (!targetCreature.Data.IsItemsFull()) { gameAction.DoCreatureExchangeItem(this.CreatureId, this.SelectedItemIndex, targetCreature.CreatureId); return(StateOperationResult.Clear()); } else { subState = SubState.SelectExchangeItem; this.TargetCreature = targetCreature; CreatureShowInfoPack pack = new CreatureShowInfoPack(targetCreature, CreatureInfoType.SelectAllItem); SendPack(pack); return(StateOperationResult.None()); } }
public override StateOperationResult OnSelectIndex(int index) { if (index < 0) { // Cancel return(StateOperationResult.None()); } switch (this.subState) { case SubActionState.SelectExchangeItem: return(OnSelectedExchangeItem(index)); case SubActionState.SelectEquipItem: return(OnSelectedEquipItem(index)); case SubActionState.SelectUseItem: return(OnSelectedUseItem(index)); case SubActionState.SelectDiscardItem: return(OnSelectedDiscardItem(index)); default: return(StateOperationResult.Pop()); } }
private StateOperationResult OnConfrimRestAll(int index) { if (index == 1) { gameAction.DoCreatureAllRest(); return(StateOperationResult.Clear()); } return(StateOperationResult.None()); }
public override StateOperationResult OnSelectIndex(int index) { switch (subState) { case SubState.ConfirmRestAll: return(OnConfrimRestAll(index)); default: break; } return(StateOperationResult.None()); }
private StateOperationResult OnSaveGameConfirmed(int index) { if (index == 1) { Debug.Log("Saving Game..."); // Save Game gameAction.SaveGame(); return(StateOperationResult.Clear()); } else { return(StateOperationResult.None()); } }
private StateOperationResult OnLoadGameConfirmed(int index) { if (index == 1) { Debug.Log("Loading Game..."); // Load Game // gameAction.LoadGame(); return(StateOperationResult.Clear()); } else { return(StateOperationResult.None()); } }
private StateOperationResult OnQuitGameConfirmed(int index) { if (index == 1) { Debug.Log("Quiting Game..."); // Quit Game SendPack(new SystemPack(SystemPack.Command.Quit)); return(StateOperationResult.Clear()); } else { return(StateOperationResult.None()); } }
public MenuItemState(IGameAction gameAction, int creatureId, FDPosition position) : base(gameAction, position) { this.CreatureId = creatureId; this.Creature = gameAction.GetCreature(creatureId); // Exchange this.SetMenu(0, MenuItemId.ItemExchange, IsMenuExchangeEnabled(), () => { CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectAllItem); SendPack(pack); subState = SubActionState.SelectExchangeItem; return(StateOperationResult.None()); }); // Use this.SetMenu(1, MenuItemId.ItemUse, IsMenuUseEnabled(), () => { CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectUseItem); SendPack(pack); subState = SubActionState.SelectUseItem; return(StateOperationResult.None()); }); // Equip this.SetMenu(2, MenuItemId.ItemEquip, IsMenuEquipEnabled(), () => { CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectEquipItem); SendPack(pack); subState = SubActionState.SelectEquipItem; return(StateOperationResult.None()); }); // Discard this.SetMenu(3, MenuItemId.ItemDiscard, IsMenuDiscardEnabled(), () => { CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectAllItem); SendPack(pack); subState = SubActionState.SelectDiscardItem; return(StateOperationResult.None()); }); }
public MenuActionState(IGameAction gameAction, int creatureId, FDPosition position) : base(gameAction, position) { this.CreatureId = creatureId; this.Creature = gameAction.GetCreature(creatureId); // Magic this.SetMenu(0, MenuItemId.ActionMagic, IsMenuMagicEnabled(), () => { CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectMagic); gameAction.GetCallback().OnHandlePack(pack); subState = SubActionState.SelectMagic; return(StateOperationResult.None()); }); // Attack this.SetMenu(1, MenuItemId.ActionAttack, IsMenuAttackEnabled(), () => { SelectAttackTargetState attackState = new SelectAttackTargetState(gameAction, this.Creature); return(StateOperationResult.Push(attackState)); }); // Item this.SetMenu(2, MenuItemId.ActionItems, IsMenuItemEnabled(), () => { MenuItemState itemState = new MenuItemState(gameAction, this.CreatureId, this.Central); return(StateOperationResult.Push(itemState)); }); // Rest this.SetMenu(3, MenuItemId.ActionRest, true, () => { // Check Treasure treasureItem = gameAction.GetTreatureAt(this.Creature.Position); if (treasureItem != null) { subState = SubActionState.ConfirmPickTreasure; return(StateOperationResult.None()); } gameAction.DoCreatureRest(this.CreatureId); return(StateOperationResult.Clear()); }); }
private StateOperationResult OnSelectedEquipItem(int index) { if (index < 0) { // Cancel the selection return(StateOperationResult.None()); } this.Creature.Data.EquipItemAt(index); // Reopen the item dialog CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectEquipItem); SendPack(pack); subState = SubActionState.SelectEquipItem; return(StateOperationResult.None()); }
public MenuRecordState(IGameAction gameAction, FDPosition position) : base(gameAction, position) { // Save Game this.SetMenu(0, MenuItemId.RecordSave, gameAction.CanSaveGame(), () => { PromptPack prompt = new PromptPack(0, ""); SendPack(prompt); this.subState = SubRecordState.SaveGame; return(StateOperationResult.None()); }); // Game Info this.SetMenu(1, MenuItemId.RecordInfo, true, () => { int turnId = gameAction.TurnId(); int chapterId = gameAction.ChapterId(); ShowBriefPack pack = new ShowBriefPack(); SendPack(pack); return(StateOperationResult.None()); }); // Load Game this.SetMenu(2, MenuItemId.RecordLoad, true, () => { PromptPack prompt = new PromptPack(0, ""); SendPack(prompt); this.subState = SubRecordState.LoadGame; return(StateOperationResult.None()); }); // Quit Game this.SetMenu(3, MenuItemId.RecordQuit, true, () => { PromptPack prompt = new PromptPack(0, ""); SendPack(prompt); this.subState = SubRecordState.QuitGame; return(StateOperationResult.None()); }); }
private StateOperationResult OnExchangeTreasureConfirmed(int index) { if (index == 0) { // Put it back TalkPack talkPack = new TalkPack(this.Creature.Clone(), MessageId.Create(MessageId.MessageTypes.Message, 7)); SendPack(talkPack); gameAction.DoCreatureRest(this.CreatureId); return(StateOperationResult.Clear()); } subState = SubActionState.ConfirmExchangeSelecting; CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectAllItem); SendPack(pack); return(StateOperationResult.None()); }
public override StateOperationResult OnSelectPosition(FDPosition position) { // Selecte position must be included in the range if (!this.ItemRange.Contains(position)) { return(StateOperationResult.Pop()); } // No creature or not a friend/NPC FDCreature targetCreature = this.gameAction.GetCreatureAt(position); if (targetCreature == null || targetCreature.Faction == Definitions.CreatureFaction.Enemy) { return(StateOperationResult.None()); } gameAction.DoCreatureUseItem(this.CreatureId, this.SelectedItemIndex, targetCreature.CreatureId); return(StateOperationResult.Clear()); }
private StateOperationResult OnPickTreasureConfirmed(int index) { if (treasureItem == null) { return(StateOperationResult.Clear()); } if (index == 1) { TalkPack pack = new TalkPack(this.Creature.Clone(), MessageId.Create(MessageId.MessageTypes.Message, 3, treasureItem.ItemId)); SendPack(pack); if (!this.Creature.Data.IsItemsFull()) { // Pick up it this.Creature.Data.Items.Add(treasureItem.ItemId); gameAction.PickTreasure(this.Creature.Position); gameAction.DoCreatureRest(this.CreatureId); return(StateOperationResult.Clear()); } else { // Confirm to exchange it subState = SubActionState.ConfirmExchangeTreature; ////PromptPack prompt = new PromptPack(this.Creature.Definition.AnimationId, ""); ////SendPack(prompt); TalkPack prompt = new TalkPack(this.Creature.Clone(), MessageId.Create(MessageId.MessageTypes.Confirm, 7)); SendPack(prompt); return(StateOperationResult.None()); } } else { // Then discard it TalkPack pack = new TalkPack(this.Creature, MessageId.Create(MessageId.MessageTypes.Message, 2)); SendPack(pack); gameAction.DoCreatureRest(this.CreatureId); return(StateOperationResult.Clear()); } }
public MenuSystemState(IGameAction gameAction, FDPosition central) : base(gameAction, central) { // Matching this.SetMenu(0, MenuItemId.SystemMatching, false, () => { subState = SubState.ConfirmMatching; MessageId message = MessageId.Create(MessageId.MessageTypes.Confirm, 1); TalkPack pack = new TalkPack(null, message); SendPack(pack); return(StateOperationResult.None()); }); // Record this.SetMenu(1, MenuItemId.SystemRecord, true, () => { ActionState nextState = new MenuRecordState(gameAction, central); return(StateOperationResult.Push(nextState)); }); // Settings this.SetMenu(2, MenuItemId.SystemSettings, true, () => { ActionState nextState = new MenuSettingsState(gameAction, central); return(StateOperationResult.Push(nextState)); }); // Rest All this.SetMenu(3, MenuItemId.SystemRestAll, true, () => { subState = SubState.ConfirmRestAll; MessageId message = MessageId.Create(MessageId.MessageTypes.Confirm, 1); TalkPack pack = new TalkPack(null, message); SendPack(pack); return(StateOperationResult.None()); }); }
public override StateOperationResult OnSelectIndex(int index) { if (subState == SubState.SelectExchangeItem) { if (index < 0) { return(StateOperationResult.None()); } int itemId = this.TargetCreature.Data.GetItemAt(index); if (itemId <= 0) { return(StateOperationResult.None()); } // Exchange the items gameAction.DoCreatureExchangeItem(this.CreatureId, this.SelectedItemIndex, TargetCreature.CreatureId, index); return(StateOperationResult.Clear()); } return(StateOperationResult.None()); }
public override StateOperationResult OnSelectPosition(FDPosition position) { if (this.AttackRange != null && this.AttackRange.Contains(position)) { FDCreature target = this.gameAction.GetCreatureAt(position); if (target != null && target.Faction == Definitions.CreatureFaction.Enemy) { // Do the attack this.gameAction.DoCreatureAttack(this.Creature.CreatureId, position); return(StateOperationResult.Clear()); } else { // Clicked in the range, but no target, let the player to click again return(StateOperationResult.None()); } } else { // Clicked out of range, cancel return(StateOperationResult.Pop()); } }
private StateOperationResult OnSelectedDiscardItem(int index) { // Discard the item this.Creature.Data.RemoveItemAt(index); return(StateOperationResult.None()); }
public override StateOperationResult OnSelectIndex(int index) { return(StateOperationResult.None()); }
public virtual StateOperationResult OnSelectIndex(int index) { return(StateOperationResult.None()); }