Exemplo n.º 1
0
    //Helper function to calculate defense resistance for damage calculation
    protected virtual float CalcResistDamage(IBattle attacker, float damage)
    {
        float typeMod = 1;

        if (currentType != IType.ElementType.NoType)
        {
            typeMod = statModifiers[(int)currentType, 1];
        }
        float defense = baseStats[1] * typeMod;

        if (attacker.currentType == this.currentType)
        {
            //Reduce damage
            defense *= 1.25f;
        }
        for (int i = 0; i < turnEffects.Count; i++)
        {
            if (turnEffects[i].statType == IType.Stat.Defense)
            {
                defense *= turnEffects[i].value;
                if (attacker.currentType == turnEffects[i].elementType)
                {
                    defense *= 1.25f;
                }
            }
        }
        damage /= defense;

        return(damage);
    }
Exemplo n.º 2
0
        /// <summary>
        /// 获取一个战场
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        static public IBattle GetBattle(Int64 id)
        {
            IBattle battle = null;

            battleMap.TryGetValue(id, out battle);
            return(battle);
        }
Exemplo n.º 3
0
        /// <summary>
        /// calculate NPC hit points based on battle mode
        /// </summary>
        /// <returns>NPC hit points</returns>
        private int CalculateNpcHitPoints(IBattle battleNpc)
        {
            int battleNpcHitPoints = 0;

            switch (NpcBattleResponse())
            {
            case BattleModeName.ATTACK:
                battleNpcHitPoints = battleNpc.Attack();
                break;

            case BattleModeName.DEFEND:
                battleNpcHitPoints = battleNpc.Defend();
                break;

            case BattleModeName.RETREAT:
                battleNpcHitPoints = battleNpc.Retreat();
                break;
            }
            if (_player.SpecialArmor == Player.Armor.High)
            {
                battleNpcHitPoints -= 2;
            }
            if (_player.SpecialArmor == Player.Armor.High)
            {
                battleNpcHitPoints -= 1;
            }

            return(battleNpcHitPoints);
        }
Exemplo n.º 4
0
    //Add Creature passed in to battle
    public bool AddCreature(GameObject obj, bool isEnemy)
    {
        bool    canAdd  = false;
        IBattle objComp = obj.GetComponent <IBattle>();

        if (isEnemy)
        {
            for (int i = 0; i < 3; i++)
            {
                if (!enemies[i])
                {
                    enemiesAdded++;
                    canAdd = true;
                    objComp.OnBattleStart(i);
                    objComp.inBattle          = true;
                    objComp.currentBattleArea = this;
                    SetEnemy(obj, i);
                    break;
                }
            }
        }
        else
        {
            //Save for summons
        }
        return(canAdd);
    }
Exemplo n.º 5
0
        public void InitBotBattle()
        {
            var userUnit = new BattleUnit()
            {
                UserName        = Context.User.Identity.Name,
                ID              = User.UserId,
                Bot             = false,
                Characteristics = ChService.GetFullUserCharacteristics(User.UserId)
            };
            var bot = new BattleUnit()
            {
                UserName        = "******",
                ID              = Guid.NewGuid().ToString(),
                Bot             = true,
                Characteristics = ChService.GetFullUserCharacteristics(User.UserId)
            };

            bot.Characteristics.Armor_head = 2;
            IBattle battle = Factory.Battle(userUnit, bot);

            Groups.Add(Context.ConnectionId, battle.ID).Wait();
            Engine.RegisterBattle(battle);
            Clients.Group(battle.ID).battleRegistered(battle.ID);

            // TODO: Modify batle! It should know who must be next.
            //Clients.Group(battle.ID).sendData(battle.ID); //Information about user. It should send who will start battle
        }
Exemplo n.º 6
0
        public void Do(IBattle battle, IHeroFSM selfFSM, IHeroFSM targetFSM)
        {
            selfFSM.HeroGraphic.Trans.DOKill();
            var pos = battle.World.GetPlayerPos(selfFSM.ID);

            selfFSM.HeroGraphic.Trans.DOMove(pos, (float)this.skillEvent.DoubleParams0 / 30f);
        }
Exemplo n.º 7
0
 //Update enemy UI in battle (updates health/energy)
 private void UpdateEnemyBar(bool[] alive, GameObject UI, int index)
 {
     if (alive[index])
     {
         if (UI.activeSelf)
         {
             //Update Bar
             IBattle enemyScript = player.GetComponent <PlayerManager>().currentBattleArea.GetEnemyScripts()[index];
             if (enemyScript)
             {
                 enemyHealthBarImages[index].GetComponent <Image>().fillAmount = enemyScript.GetHealth() / enemyScript.MAX_HEALTH;
                 enemyEnergyBarImages[index].GetComponent <Image>().fillAmount = enemyScript.GetEnergy() / enemyScript.MAX_ENERGY;
                 enemyHealthBarText[index].GetComponent <Text>().text          = Mathf.Ceil(enemyScript.GetHealth()).ToString();
                 enemyEnergyBarText[index].GetComponent <Text>().text          = Mathf.Ceil(enemyScript.GetEnergy()).ToString();
             }
         }
         else
         {
             UI.SetActive(true);
         }
     }
     else
     {
         if (UI.activeSelf)
         {
             UI.SetActive(false);
         }
     }
 }
Exemplo n.º 8
0
 //Trigger Debuffs/DoT for given creature
 private void LowerEffects(IBattle obj)
 {
     for (int j = obj.turnEffects.Count - 1; j >= 0; j--)
     {
         if (obj.turnEffects[j].numUses - 1 <= 0)
         {
             //remove
             obj.turnEffects.RemoveAt(j);
         }
         else
         {
             obj.turnEffects[j].numUses -= 1;
         }
     }
     for (int j = obj.turnDamage.Count - 1; j >= 0; j--)
     {
         if (obj.turnDamage[j].numUses - 1 <= 0)
         {
             //remove
             obj.turnDamage.RemoveAt(j);
         }
         else
         {
             obj.turnDamage[j].numUses -= 1;
         }
     }
 }
        private int CalculateNpcHitPoints(IBattle battleNpc)
        {
            int battleNpcHitPoints = 0;

            if (battleNpc is Enemy /*playerHitPoints >= battleNpcHitPoints*/)
            {
                Enemy battlingNpc = _currentNpc as Enemy;


                switch (NpcBattleResponse())
                {
                case BattleModeName.ATTACK:
                    battleNpcHitPoints = battleNpc.Attack();

                    break;

                case BattleModeName.DEFEND:
                    battleNpcHitPoints = battleNpc.Defend();

                    break;

                case BattleModeName.RETREAT:
                    battleNpcHitPoints = battleNpc.Retreat();
                    break;
                }
            }
            return(battleNpcHitPoints);
        }
Exemplo n.º 10
0
        public BattleResult Execute(IMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            IBattle battle = ValidateAndGet(message);

            if (battle != null)
            {
                PreExecution(message, battle);
                IExecutableMessage execMessage = message as IExecutableMessage;
                if (execMessage != null)
                {
                    execMessage.Execute(battle);
                }
                PostExecution(message, battle);
                var result = battle.GetResult();
                Dictionary <string, Reward> reward = null;
                if (battle.Status == BattleStatus.Killed)
                {
                    UnregisterBattle(battle.ID);
                    reward = GenerateReward(battle);
                }
                return(new BattleResult()
                {
                    Result = result, UserSpecificReward = reward, UsersStates = battle.Units
                });
            }
            throw new ArgumentException("message"); //change to a custom error
        }
Exemplo n.º 11
0
        private IBattle ValidateAndGet(IMessage message)
        {
            IBattle battle = null;

            Battles.TryGetValue(message.BattleId, out battle);
            return(battle);
        }
Exemplo n.º 12
0
        /// <summary>
        /// battle method
        /// </summary>
        private void Battle()
        {
            if (_currentNPC is IBattle)
            {
                IBattle battleNPC          = _currentNPC as IBattle;
                int     playerHitPoints    = 0;
                int     battleNpcHitPoints = 0;
                playerHitPoints    = CalculatePlayerHitPoints();
                battleNpcHitPoints = CalculateNPCHitPoints(battleNPC);

                //bool battling = false;
                //do
                //{

                //    CurrentLocationInformation =
                //    $"Player: {_player.BattleMode}     Hit Points: {playerHitPoints}" + Environment.NewLine +
                //    $"NPC: {battleNPC.BattleMode}     Hit Points: {battleNpcHitPoints}" + Environment.NewLine;
                //} while (!battling);

                if (playerHitPoints >= battleNpcHitPoints)
                {
                    _currentLocation.NPCS.Remove(_currentNPC);
                    DetermineRewards();
                }
                else
                {
                    DetermineLosses();
                }
            }
            else
            {
                CurrentLocationInformation = "It seems the enemy is not ready to meet us in battle, try again later.";
            }
        }
 public EffectContext(IBattle battle, IBattlePokemon user, IMove move, IReadOnlySet <IBattlePokemon> targets)
 {
     Battle  = battle;
     User    = user;
     Move    = move;
     Targets = targets;
 }
Exemplo n.º 14
0
 protected BattleEvent(IBattle battle, ICombatant combatant, IntVector2 startPosition, IntVector2 endPosition)
 {
     Battle        = battle;
     Combatant     = combatant;
     StartPosition = startPosition;
     EndPosition   = endPosition;
 }
        private void Battle()
        {
            // check to see if an NPC can battle
            if (_currentNpc is IBattle)
            {
                IBattle battleNpc          = _currentNpc as IBattle;
                int     playerHitPoints    = 0;
                int     battleNpcHitPoints = 0;
                string  battleInformation  = "";

                // caculate hit points if the player and NPC have weapons
                if (_player.CurrentWeapon != null)
                {
                    playerHitPoints = CalculatePlayerHitPoints();
                }
                else
                {
                    battleInformation = "It appears you are entering into a battle without a weapon.";
                }

                if (battleNpc.CurrentWeapon != null)
                {
                    battleNpcHitPoints = CaculateNpcHitPoints(battleNpc);
                }
                else
                {
                    battleInformation = $"It appears you are entering into battle with {_currentNpc.Name} who has no weapon.";
                }

                // build out the text  for the current location information
                battleInformation +=
                    $"Player: {_player.BattleMode} Hit Points: {playerHitPoints}" + Environment.NewLine +
                    $"NPC: {battleNpc.BattleMode}  Hit Points: {battleNpcHitPoints}" + Environment.NewLine;

                // deterrmine results of battle
                if (playerHitPoints >= battleNpcHitPoints)
                {
                    battleInformation += $"You have killed {_currentNpc.Name}.";
                    _currentLocation.Npcs.Remove(_currentNpc);
                }
                else
                {
                    battleInformation += $"You have killed by {_currentNpc.Name}.";
                    _player.Lives--;
                }

                CurrentLocationInformation = battleInformation;
                if (_player.Lives <= 0)
                {
                    OnPlayerDies("You have been slain and have no lives left");
                }

                else
                {
                    CurrentLocationInformation = "The current NPC will is not battle ready. Seems you are a bit jumpy and your experience suffers.";
                    _player.Experience        -= 10;
                }
            }
        }
Exemplo n.º 16
0
 public void Do(IBattle battle, IHeroFSM selfFSM, IHeroFSM targetFSM)
 {
     targetFSM.HeroGraphic.PlayAction("behurt");
     IEnumeratorTool.StartCoroutine(CheckAniEnd(targetFSM, "behurt", () =>
     {
         targetFSM.HeroGraphic.PlayAction("idle");
     }));
 }
Exemplo n.º 17
0
        private void Battle()
        {
            if (CurrentNpc is IBattle)
            {
                IBattle battleNpc = CurrentNpc as IBattle;
                int     playerHitPoints;
                int     battleNpcHitPoints = 0;
                string  battleInformation  = "";

                playerHitPoints = CalculatePlayerHitPoints();
                if (battleNpc.CurrentWeapon != GameData.GameItemById(1000) as Weapon)
                {
                    battleNpcHitPoints = CalculateNpcHitPoints(battleNpc);
                }
                else
                {
                    battleInformation = "It appears you are attacking an unarmed assailant" + Environment.NewLine;
                }
                battleInformation +=
                    $"Player: {Player.BattleMode}        Hit Points:  {playerHitPoints} " + Environment.NewLine +
                    $"NPC: {battleNpc.BattleMode}        Hit Points:  {battleNpcHitPoints} " + Environment.NewLine;

                if (playerHitPoints >= battleNpcHitPoints)
                {
                    battleInformation += $"You have slain {CurrentNpc.Name}" + Environment.NewLine +
                                         "Check the items tab, the slain NPC may have dropped something";

                    //defeated Npc drops items
                    if (CurrentNpc.Inventory != null)
                    {
                        foreach (var gameItem in CurrentNpc.Inventory)
                        {
                            _currentLocation.AddGameItemToLocation(gameItem);
                        }
                    }
                    if (CurrentNpc.Id == 3003)
                    {
                        _currentLocation.Npcs.Add(GameData.NpcById(1008));
                    }
                    _currentLocation.Npcs.Remove(CurrentNpc);
                }
                else
                {
                    battleInformation += $"You have been slain by {_currentNpc.Name}";
                    Player.Lives--;
                    OnPlayerDies("You have been slain.");
                }
                CurrentLocationInformation = battleInformation;
                if (Player.Lives <= 0)
                {
                    OnPlayerDies("You have been slain.");
                }
            }
            else
            {
                CurrentLocationInformation = "The current NPC is not battle ready";
            }
        }
Exemplo n.º 18
0
 public InflictMoveDamage(IBattle battle, IMove move, Slot user, IEnumerable <Slot> targets)
 {
     Battle         = battle;
     this.move      = move;
     User           = user;
     this.targets   = new List <Slot>(targets).AsReadOnly();
     RandomModifier = 1.0f - (battle.RNG.Next(16) / 100.0f);
     IsCriticalHit  = battle.RNG.NextDouble() < CriticalHitProbability(move.CriticalHitStage);
 }
Exemplo n.º 19
0
    private void CreateBattle()
    {
        var id = BattleFactory.CreateBattle(battleWorldId: 1);

        battle = BattleFactory.GetBattle(id);
        var input = new BattleInput(battle);

        battle.Input = input;
    }
Exemplo n.º 20
0
    private void Awake()
    {
        UnitView.Preload();

        _battle = new Battle(_unitContainer);
        _button.onClick.AddListener(GameStart);

        GameStart();
    }
Exemplo n.º 21
0
        public Inventar(string Text, MainWindow mainWindow, IBattle Object)
            : this()
        {
            label1.Text = Text;
            this.Object = Object;

            PictureType       = new Dictionary <string, System.Drawing.Bitmap[]>();
            comboBox1.Enabled = false;
            MainWindow        = mainWindow;
        }
Exemplo n.º 22
0
        //
        public BattleInput(IBattle battle)
        {
            this.battle  = battle;
            cmdCacheList = new List <Cmd>();
            InputSate    = new DataDrive_Service();


            //所有状态
            this.InputSate.RegisterData("OnInput");
        }
Exemplo n.º 23
0
        public HeroFSM_TBS(int camp, HeroLogic logic, HeroGraphic graphic, IBattle battle)
        {
            this.Camp        = camp;
            this.HeroLogic   = logic;
            this.HeroGraphic = graphic;
            this.battle      = battle;

            inputProcessMap             = new Dictionary <string, Action <List <object> > >();
            inputProcessMap["UseSkill"] = OnUseSkill;
        }
Exemplo n.º 24
0
        public void DisplayTalkToEnemy(Enemy enemy)
        {
            ISpeak speakingEnemy = enemy as ISpeak;
            string message       = speakingEnemy.Speak();

            IBattle battlingEnemy = enemy as IBattle;
            string  attackMessage = battlingEnemy.AttackMessage;

            DisplayGamePlayScreen("Speak to Character", message + "\n " + attackMessage, ActionMenu.AttackMenu, "");
        }
Exemplo n.º 25
0
        public void Dispose()
        {
            int count = this._entities.Count;

            for (int i = 0; i < count; i++)
            {
                Entity.Destroy(this._entities[i]);
            }
            this.DestroyEnties();
            this._battle = null;
        }
Exemplo n.º 26
0
        private void Battle()
        {
            // check if an NPC can battle
            if (_currentNPC is IBattle)
            {
                IBattle battleNPC          = _currentNPC as IBattle;
                int     playerHitPoints    = 0;
                int     battleNPCHitPoints = 0;
                string  battleInformation  = "";

                // calculate hit points if the player and NPC have weapons
                if (_player.CurrentWeapon != null)
                {
                    playerHitPoints = CalculatePlayerHitPoints();
                }
                else
                {
                    battleInformation = "It appears you're entering into battle without a weapon.";
                }

                if (battleNPC.CurrentWeapon != null)
                {
                    battleNPCHitPoints = CalculateNPCHitPoints(battleNPC);
                }
                else
                {
                    battleInformation = $"It appears you're entering into battle with {_currentNPC.Name} who has no weapon.";
                }

                // build out text for current location information
                battleInformation +=
                    $"Player: {_player.BattleMode}  Hit Points: {playerHitPoints}" + Environment.NewLine +
                    $"NPC: {battleNPC.BattleMode}   Hit Points: {battleNPCHitPoints}" + Environment.NewLine;

                // determine results of battle
                if (playerHitPoints >= battleNPCHitPoints)
                {
                    battleInformation += $"You've defeated {_currentNPC.Name}.";
                    _currentLocation.NPCs.Remove(_currentNPC);
                }

                CurrentLocationInformation = battleInformation;
                if (_player.Health <= 0)
                {
                    OnPlayerDies($"You have been defeated by {_currentNPC.Name}.");
                }
            }
            else
            {
                CurrentLocationInformation = "The NPC isn't ready to fight. -10 experience.";
                _player.ExperiencePoints  -= 10;
            }
        }
Exemplo n.º 27
0
        private void Battle()
        {
            if (_currentNPC is IBattle)
            {
                IBattle battleNPC          = _currentNPC as IBattle;
                int     playerHitPoints    = _player.Health;
                int     battleNPCHitPoints = 0;
                string  battleInformation  = "";

                //if (_player.CurrentWeapon != null)
                //{
                //    playerHitPoints = CalculatePlayerHitPoints();
                //}
                //else
                //{
                //    battleInformation = "You are entering battle without a weapon!";
                //}

                if (battleNPC.CurrentWeapon != null)
                {
                    battleNPCHitPoints = CalculateNPCHitPoints(battleNPC);
                }
                else
                {
                    battleInformation = $"You are entering battle against {_currentNPC.Name} who appears to be unarmed.";
                }

                battleInformation +=
                    $"\nPlayer: {_player.BattleMode}      Hit Points: {playerHitPoints}" + Environment.NewLine +
                    $"NPC: {battleNPC.BattleMode}       Hit Points: {battleNPCHitPoints}" + Environment.NewLine;

                if (playerHitPoints >= battleNPCHitPoints)
                {
                    battleInformation += $"You have slain {_currentNPC.Name}";
                    _currentLocation.NPCs.Remove(_currentNPC);
                }
                else
                {
                    battleInformation += $"You have been slain by {_currentNPC.Name}";
                    _player.Health     = 0;
                }
                CurrentLocationInformation = battleInformation;
                if (_player.Health <= 0)
                {
                    OnPlayerDies("You have been slain.");
                }
            }
            else
            {
                CurrentLocationInformation = "This NPC is angry that you tried to attack them \nand smacked you across the face!";
                _player.Health            -= 5;
            }
        }
Exemplo n.º 28
0
        public void BeforeEachTest()
        {
            _battleMock        = new Mock <IBattle>();
            _battle            = _battleMock.Object;
            _battleServiceMock = new Mock <IBattleService>();
            _battleServiceMock.Setup(service => service.SetupRandomBattle()).Returns(_battle);

            _window = new MainWindow(_battleServiceMock.Object);
            _window.Show();

            _fightRoundButton = _window.GetPrivateFieldValueByName <Button>("FightRoundButton");
        }
Exemplo n.º 29
0
 public BattleEffect(IBattle attacker, IType.Stat affectedStat, float val, IType.ElementType element, int turnsActive = 3)
 {
     statType      = affectedStat;
     value         = val;
     elementType   = element;
     numUses       = turnsActive;
     this.attacker = attacker;
     if (numUses < 0)
     {
         numUses = 0;
     }
 }
Exemplo n.º 30
0
 //Get IBattle scripts of each enemy
 public IBattle[] GetEnemyScripts()
 {
     IBattle[] enemyScripts = new IBattle[3];
     for (int i = 0; i < 3; i++)
     {
         if (enemies[i])
         {
             enemyScripts[i] = enemies[i].GetComponent <IBattle>();
         }
     }
     return(enemyScripts);
 }
 private int GetAttackerLossesForBattle(IBattle battle)
 {
     return battle.Attackers.Sum(a => a.Key.Cost * a.Value) - battle.SurvivingAttackers.Sum(a => a.Key.Cost * a.Value);
 }
 private int GetDefenderLossesForBattle(IBattle battle)
 {
     return battle.Defenders.Sum(a => a.Key.Cost * a.Value) - battle.SurvivingDefenders.Sum(a => a.Key.Cost * a.Value);
 }