示例#1
0
文件: Action.cs 项目: xposure/Demo
 public bool Check(Level level, Character actor)
 {
     return Condition(level, actor, Ability);
 }
示例#2
0
文件: Character.cs 项目: xposure/Demo
        public void Turn(Level level, float dt)
        {
            //check if ability is still valid
            if (currentAction > -1 && !ActionList[currentAction].Ability.CanUse(level, this, currentTarget))
            {
                //cancel
                currentAction = -1;
                AP = 0;
                currentTarget = null;
            }

            //will check all actions or the 1 up to the currentAction (for canceling)
            var maxAction = currentAction == -1 ? ActionList.Count : currentAction;
            for (var i = 0; i < maxAction; i++)
            {
                //found either a new action to run or higher priority action
                if (ActionList[i].Check(level, this))
                {
                    if (currentAction > -1)
                    {
                        //cancel (don't clear target because Check set the new one)
                    }

                    currentAction = i;
                    AP = 0;
                    break;
                }
            }

            if (currentAction > -1)
            {
                var action = ActionList[currentAction];
                var ability = action.Ability;

                LastAction = ability.Name;

                var distance = Vector2.Distance(Position, currentTarget.Position);
                if (distance > ability.MaxDistance)
                {
                    //move closer
                    var dir = (currentTarget.Position - Position);
                    dir.Normalize();

                    dir *= (dt * 100);
                    Position += dir;
                }
                else
                {
                    AP += ability.ChargeRate * APRechargeRate * dt;

                    if (AP >= 100)
                    {
                        ability.Use(level, this, currentTarget);
                        AP = 0;
                        currentTarget = null;
                        currentAction = -1;
                        Turn(level, dt);
                    }
                }
            }
            else
            {
                LastAction = "Idle";
            }
        }
示例#3
0
文件: Program.cs 项目: xposure/Demo
        static void Main(string[] args)
        {
            var level = new Level();

            var enemies = new List<Character>();
            for (var i = 0; i < 5; i++)
            {
                var ch = CreateEnemy("Enemy " + i);

                ch.ActionList.Add(new Action2(Condition.FoeNearest, new AbilityAttack()));
                //ch.ActionList.Add(Action.HealSelf);
                enemies.Add(ch);
            }

            //enemies[enemies.Count - 1].ActionList.Insert(0, new Action()
            //{
            //    Ability = new AbilityHeal(),
            //    Condition = new ConditionHPLessThan(75),
            //    Target = new TargetAliveEnemy(),
            //});
            level.enemy = new CharacterGroup(enemies.ToArray());

            var players = new List<Character>();
            for (var i = 0; i < 3; i++)
            {
                var ch = CreatePlayer("Player " + i);
                if (i > 0)
                    ch.ActionList.Add(new Action2(Condition.FoePartyLeaderTarget, new AbilityAttack()));

                ch.ActionList.Add(new Action2(Condition.FoeNearest, new AbilityAttack()));
                //ch.ActionList.Add(Action.HealSelf);
                players.Add(ch);
            }

            //players[0].APRechargeRate = 1.5f;
            players[0].ActionList.Add(new Action2(Condition.AllyAnyLessThan90, new AbilityHeal()));
            level.player = new CharacterGroup(players.ToArray());

            var line = string.Empty;
            while (!Console.KeyAvailable)
            {
                System.Console.Clear();
                //Console.WriteLine();

                foreach (var enemy in enemies)
                {
                    if (enemy.IsAlive)
                        enemy.Turn(level);
                }

                foreach (var player in players)
                {
                    if (player.IsAlive)
                        player.Turn(level);
                }

                //Console.WriteLine();

                foreach (var enemy in enemies)
                    //if (enemy.IsAlive)
                        Console.WriteLine(enemy);

                foreach (var player in players)
                    //if (player.IsAlive)
                        Console.WriteLine(player);

                System.Threading.Thread.Sleep(500);
            }
        }