public override void Update(IGameInterface gameInterface) { if (IsCurrentMoveDone()) { // Set precise position for the UI if (currentVertex >= 0) { var vertex = this.MovePath.Vertexes[currentVertex]; this.UICreature.SetPixelPosition(FieldTransform.GetCreaturePixelPosition(vertex)); } // Pick the next vertex, or finish currentVertex++; if (currentVertex < this.MovePath.Vertexes.Count) { var targetVertex = this.MovePath.Vertexes[currentVertex]; targetPosition = FieldTransform.GetCreaturePixelPosition(targetVertex); FDPosition current = this.UICreature.GetCurrentPosition(); if (targetVertex.X > current.X) { this.UICreature.SetAnimateState(UICreature.AnimateStates.WalkRight); } else if (targetVertex.X < current.X) { this.UICreature.SetAnimateState(UICreature.AnimateStates.WalkLeft); } else if (targetVertex.Y > current.Y) { this.UICreature.SetAnimateState(UICreature.AnimateStates.WalkDown); } else if (targetVertex.Y < current.Y) { this.UICreature.SetAnimateState(UICreature.AnimateStates.WalkUp); } else { // Make the status to done so that next Update will pick the next vertex this.UICreature.SetAnimateState(UICreature.AnimateStates.Idle); } } else { this.UICreature.SetAnimateState(UICreature.AnimateStates.Idle); this.HasFinished = true; } return; } DoMoving(); }
public UIMenuItem PlaceMenuItem(MenuItemId menuItemId, FDPosition position, FDPosition showUpPosition, bool enabled, bool selected) { GameObject obj = new GameObject(); obj.transform.parent = fieldObjectsRoot; var menuItem = obj.AddComponent <UIMenuItem>(); menuItem.Initialize(this, menuItemId, position, showUpPosition, enabled, selected); cancellableObjects.Add(obj); return(menuItem); }
public override StateOperationResult OnSelectPosition(FDPosition position) { for (int index = 0; index < 4; index++) { if (this.MenuItemEnabled[index] && this.MenuItemPositions[index].AreSame(position)) { // Clicked on menu return(this.MenuActions[index]()); } } // Cancell the menu return(StateOperationResult.Pop()); }
public UICreature PlaceCreature(int creatureId, int animationId, FDPosition position) { GameObject creatureObj = new GameObject(); creatureObj.name = string.Format(@"creature_{0}", creatureId); creatureObj.transform.parent = fieldObjectsRoot; creatureObj.transform.localPosition = FieldTransform.GetCreaturePixelPosition(position); var creatureCom = creatureObj.AddComponent <UICreature>(); creatureCom.Initialize(this, creatureId, animationId); //// creatureCom.SetAnimateState(UICreature.AnimateStates.Dying); return(creatureCom); }
private void WalkOnPosition(FDPosition position, int leftMovePoint, FDMoveRange range) { int moveCost = GetMoveCost(position, creature); if (moveCost == -1 || leftMovePoint < moveCost) { // Nothing to walk return; } // If this is ZOC, stop the move if (!position.AreSame(this.creature.Position) && HasAdjacentEnemy(position)) { return; } int leftPoint = leftMovePoint - moveCost; foreach (FDPosition direction in position.GetAdjacentPositions()) { if (direction.X <= 0 || direction.X > gameField.Width || direction.Y <= 0 || direction.Y > gameField.Height) { continue; } if (range.Contains(direction)) { continue; } // If already occupied by creature FDCreature existing = gameAction.GetCreatureAt(direction); if (existing != null && existing.IsOppositeFaction(creature)) { continue; } if (GetMoveCost(direction, creature) == -1) { // Cannot land on target direction continue; } range.AddPosition(direction, position); positionQueue.Enqueue(new MoveRangeQueueObject(direction, leftPoint)); } }
public MenuState(IGameAction gameAction, FDPosition central) : base(gameAction) { this.Central = central; this.MenuItemPositions = new FDPosition[4] { FDPosition.At(Central.X - 1, Central.Y), FDPosition.At(Central.X, Central.Y - 1), FDPosition.At(Central.X + 1, Central.Y), FDPosition.At(Central.X, Central.Y + 1), }; this.MenuItemIds = new MenuItemId[4]; this.MenuActions = new Func <StateOperationResult> [4]; this.MenuItemEnabled = new bool[4]; }
public float GetDistanceTo(FDPosition position) { if (distanceDict == null) { return(0); } if (distanceDict.ContainsKey(position)) { return(distanceDict[position]); } else { // Distance Max return(999); } }
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()); }); }
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()); }); }
private static AttackInformation AttackFrom(FDCreature subject, FDCreature target, GameField field) { bool isHit = FDRandom.BoolFromRate(subject.Data.CalculatedHit - target.Data.CalculatedEv); bool isCritical = FDRandom.BoolFromRate(commonCriticalAttackRate); int reduceHp = 0; if (isHit) { FDPosition pos = subject.Position; ShapeDefinition shape = field.GetShapeAt(pos.X, pos.Y); int adjustedAp = subject.Data.CalculatedAp * (100 + shape.AdjustedAp) / 100; FDPosition targetPos = target.Position; ShapeDefinition targetShape = field.GetShapeAt(targetPos.X, targetPos.Y); int adjustedDp = target.Data.CalculatedDp * (100 + shape.AdjustedDp) / 100; int attackMax = adjustedAp - adjustedDp; int attackMin = (int)(attackMax * 0.9f); reduceHp = FDRandom.IntFromSpan(attackMin, attackMax); reduceHp = (reduceHp < 0) ? 0 : reduceHp; if (isCritical) { reduceHp *= 2; } // Poisoned AttackItemDefinition attackItem = subject.Data.GetAttackItem(); if (attackItem != null) { bool isPoisoned = FDRandom.BoolFromRate(attackItem.GetPoisonRate()); if (isPoisoned) { target.Data.SetEffect(CreatureData.CreatureEffects.Poisoned); } } } AttackInformation info = new AttackInformation(target.Data.Hp, target.Data.Hp - reduceHp, isCritical); target.Data.UpdateHp(-reduceHp); return(info); }
private bool HasAdjacentEnemy(FDPosition position) { foreach (FDPosition direction in position.GetAdjacentPositions()) { FDCreature c = gameAction.GetCreatureAt(direction); if (c == null) { continue; } if (this.creature.IsOppositeFaction(c)) { return(true); } } return(false); }
public void ResolveDistanceFrom(FDPosition originPos, FDPosition terminatePos) { this.originalPosition = originPos; this.distanceDict = new Dictionary <FDPosition, float>(); this.positionQueue = new Queue <FDPosition>(); this.SetKey(originPos, 0); while (positionQueue.Count > 0) { FDPosition pos = positionQueue.Dequeue(); this.Walk(pos); if (pos.AreSame(terminatePos)) { break; } } }
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()); }); }
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 void Walk(FDPosition position) { if (!distanceDict.ContainsKey(position)) { return; } float val = distanceDict[position]; this.SetKey(FDPosition.At(position.X - 1, position.Y), val + 1); this.SetKey(FDPosition.At(position.X, position.Y - 1), val + 1); this.SetKey(FDPosition.At(position.X + 1, position.Y), val + 1); this.SetKey(FDPosition.At(position.X, position.Y + 1), val + 1); this.SetKey(FDPosition.At(position.X - 1, position.Y - 1), val + 1.4f); this.SetKey(FDPosition.At(position.X + 1, position.Y - 1), val + 1.4f); this.SetKey(FDPosition.At(position.X + 1, position.Y + 1), val + 1.4f); this.SetKey(FDPosition.At(position.X - 1, position.Y + 1), val + 1.4f); }
public void DoCreatureAttack(int creatureId, FDPosition targetPosition) { FDCreature creature = this.GetCreature(creatureId); if (creature == null) { throw new ArgumentNullException("creature"); } FDCreature target = this.GetCreatureAt(targetPosition); if (target == null) { throw new ArgumentNullException("target"); } FightInformation fighting = DamageFormula.DealWithAttack(creature, target, gameField, true); BattleFightPack fightPack = new BattleFightPack(creature, target, fighting); gameCallback.OnHandlePack(fightPack); // Remove dead creature if (target.Data.Hp <= 0) { this.DisposeCreature(target.CreatureId, true, true); } if (creature.Data.Hp <= 0) { this.DisposeCreature(creature.CreatureId, true, true); } if (creature.Faction == CreatureFaction.Friend) { // Talk about experience MessageId mId = MessageId.Create(MessageId.MessageTypes.Message, 5, 33); TalkPack talk = new TalkPack(creature, mId); gameCallback.OnHandlePack(talk); } PostCreatureAction(creature); }
public FDMoveRange CalculateMoveRange() { FDPosition central = this.creature.Position; FDMoveRange range = new FDMoveRange(central); int movePoint = creature.Data.CalculatedMv; positionQueue = new Queue <MoveRangeQueueObject>(); range.AddPosition(central, null); positionQueue.Enqueue(new MoveRangeQueueObject(central, movePoint)); while (positionQueue.Count > 0) { MoveRangeQueueObject queueObject = positionQueue.Dequeue(); WalkOnPosition(queueObject.Position, queueObject.LeftMovePoint, range); } // Remove the friend creatures from range List <FDCreature> creatureInRange = gameAction.GetCreatureInRange(range, creature.Faction); if (creature.Faction == CreatureFaction.Friend) { creatureInRange.AddRange(gameAction.GetCreatureInRange(range, CreatureFaction.Npc)); } else if (creature.Faction == CreatureFaction.Npc) { creatureInRange.AddRange(gameAction.GetCreatureInRange(range, CreatureFaction.Friend)); } foreach (FDCreature c in creatureInRange) { if (c.CreatureId == creature.CreatureId) { continue; } range.AddSkipPosition(c.Position); } return(range); }
public override StateOperationResult OnSelectPosition(FDPosition position) { // If position is in range if (moveRange.Contains(position)) { ClearRangePack clear = new ClearRangePack(); SendPack(clear); FDMovePath movePath = moveRange.GetPath(position); gameAction.CreatureWalk(new SingleWalkAction(creature.CreatureId, movePath)); var nextState = new MenuActionState(gameAction, creature.CreatureId, position); return(new StateOperationResult(StateOperationResult.ResultType.Push, nextState)); } else { // Cancel return(new StateOperationResult(StateOperationResult.ResultType.Pop)); } }
public void TouchCreature(int creatureId) { if (currentDialog != null) { return; } UICreature creature = GetUICreature(creatureId); FDPosition creaturePosition = creature.GetCurrentPosition(); FDPosition cursorPosition = FieldTransform.GetObjectUnitPosition(gameCursor.transform.localPosition); if (!creaturePosition.AreSame(cursorPosition)) { gameCursor.transform.localPosition = FieldTransform.GetObjectPixelPosition(FieldTransform.FieldObjectLayer.Ground, creaturePosition.X, creaturePosition.Y); } else { // Do the actuall game event gameManager.HandleOperation(creaturePosition); } }
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 void Start(IGameInterface gameInterface) { if (pack == null) { return; } menuItems = new UIMenuItem[4]; FDPosition pos = pack.Position; FDPosition[] positions = new FDPosition[4] { FDPosition.At(pos.X - 1, pos.Y), FDPosition.At(pos.X, pos.Y - 1), FDPosition.At(pos.X + 1, pos.Y), FDPosition.At(pos.X, pos.Y + 1) }; bool hasSelected = false; for (int i = 0; i < 4; i++) { MenuItemId itemId = pack.MenuItems[i]; bool enabled = pack.Enabled[i]; bool isSelected = false; if (enabled && !hasSelected) { isSelected = true; hasSelected = true; } // Place the Menu on map menuItems[i] = gameInterface.PlaceMenuItem(itemId, positions[i], pos, enabled, isSelected); } for (int i = 0; i < 4; i++) { menuItems[i].RelatedMenuItems = menuItems; } }
public FDCreature(int creatureId, CreatureFaction faction, CreatureDefinition definition, FDPosition position) { this.Faction = faction; this.Data = new CreatureData(); this.Data = CreatureData.FromDefinition(creatureId, definition); this.Definition = definition; this.Position = position; this.PreMovePosition = position; this.Data.LastGainedExperience = 0; if (this.Definition.Occupation == 154 || this.Definition.Occupation == 155 || this.Definition.DefinitionId == 747) { this.Data.AIType = CreatureData.AITypes.AIType_Defensive; } else { this.Data.AIType = CreatureData.AITypes.AIType_Aggressive; } }
public FDCreature GetCreatureAt(FDPosition position) { FDCreature creature = this.Friends.Find(c => { return(c.Position.AreSame(position)); }); if (creature != null) { return(creature); } creature = this.Enemies.Find(c => { return(c.Position.AreSame(position)); }); if (creature != null) { return(creature); } creature = this.Npcs.Find(c => { return(c.Position.AreSame(position)); }); if (creature != null) { return(creature); } return(null); }
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()); } }
public void Initialize(IGameInterface gameInterface, MenuItemId menuItemId, FDPosition position, FDPosition showUpPosition, bool enabled, bool selected) { this.gameInterface = gameInterface; this.gameObject.name = string.Format(@"menuitem_{0}", menuItemId.GetHashCode()); this.gameObject.transform.localPosition = FieldTransform.GetGroundPixelPosition(showUpPosition); Vector3 menuLocalPosition = FieldTransform.GetGroundPixelPosition(position); MenuSliding sliding = this.gameObject.AddComponent <MenuSliding>(); sliding.Initialize(menuLocalPosition); this.isEnabled = enabled; this.isSelected = selected; this.position = position; this.menuItemId = menuItemId; var box = this.gameObject.AddComponent <BoxCollider>(); box.size = new Vector3(2.4f, 0.2f, 2.4f); box.center = new Vector3(0f, 0.2f, 0f); }
// Start is called before the first frame update void Start() { DefinitionStore.Instance.LoadChapter(25); //DefinitionStore.Instance.LoadChapter(18); //CreatureDefinition def = DefinitionStore.Instance.GetCreatureDefinition(50508); FDCreature subject = new FDCreature(4, CreatureFaction.Friend, DefinitionStore.Instance.GetCreatureDefinition(15), FDPosition.At(0, 0)); FDCreature target = new FDCreature(11, CreatureFaction.Enemy, DefinitionStore.Instance.GetCreatureDefinition(52502), FDPosition.At(0, 0)); int hp1 = target.Data.HpMax; int hp2 = hp1 / 2; int hp3 = hp2 / 2; int hp4 = subject.Data.HpMax; int hp5 = hp4 / 2; int hp6 = hp5 / 2; Debug.Log(string.Format(@"hp1: {0}, hp2: {1}, hp3: {2}", hp1, hp2, hp3)); AttackInformation a1 = new AttackInformation(hp1, hp2, false); AttackInformation a2 = new AttackInformation(hp2, hp3, false); AttackInformation b1 = new AttackInformation(hp4, hp5, false); AttackInformation b2 = new AttackInformation(hp5, hp6, false); FightInformation fightInfo = new FightInformation(a1, a2, b1, b2); this.Initialize(subject, target, fightInfo); fightPhase = FightPhase.Attack1; Invoke("DoSubjectAttack", 1.2f); }
public MoveRangeQueueObject(FDPosition pos, int left) { this.Position = pos; this.LeftMovePoint = left; }
public bool CanCreatureSpellMagic(int creatureId, int magicId, FDPosition targetPosition) { return(true); }
public bool CanCreatureAttack(int creatureId, FDPosition targetPosition) { return(true); }
/// <summary> /// To update the treasure box /// </summary> /// <param name="position"></param> /// <param name="itemId"></param> public void UpdateTreasure(FDPosition position, int itemId) { }