コード例 #1
0
ファイル: derpAI.cs プロジェクト: nlacombe42/forgottenschism
        private static bool isOrgPresent(CharMap cmap, Point p, String org)
        {
            if (p.X < 0 || p.Y < 0 || p.X >= cmap.NumX || p.Y >= cmap.NumY)
                return false;

            if (!cmap.isChar(p.X, p.Y))
                return false;

            return cmap.get(p.X, p.Y).Organization == org;
        }
コード例 #2
0
ファイル: derpAI.cs プロジェクト: nlacombe42/forgottenschism
        private static Point targetCharacter(Character c, Point p, CharMap cmap)
        {
            bool targetable = false;
            bool castable = false;
            List<Point> targetableChar = new List<Point>();
            Point target = new Point(-1, -1);

            if (c is Fighter || c is Scout)
            {
                if (cmap.isChar(p.X - 1, p.Y) && cmap.get(p.X - 1, p.Y).Organization == "main")
                {
                    targetable = true;
                    targetableChar.Add(new Point(p.X - 1, p.Y));
                }
                if (cmap.isChar(p.X, p.Y - 1) && cmap.get(p.X, p.Y - 1).Organization == "main")
                {
                    targetable = true;
                    targetableChar.Add(new Point(p.X, p.Y - 1));
                }
                if (cmap.isChar(p.X + 1, p.Y) && cmap.get(p.X + 1, p.Y).Organization == "main")
                {
                    targetable = true;
                    targetableChar.Add(new Point(p.X + 1, p.Y));
                }
                if (cmap.isChar(p.X, p.Y + 1) && cmap.get(p.X, p.Y + 1).Organization == "main")
                {
                    targetable = true;
                    targetableChar.Add(new Point(p.X, p.Y + 1));
                }
            }
            else if (c is Archer)
            {
                if (cmap.isChar(p.X - 1, p.Y + 1) && cmap.get(p.X - 1, p.Y + 1).Organization == "main")
                {
                    targetable = true;
                    targetableChar.Add(new Point(p.X - 1, p.Y + 1));
                }
                if (cmap.isChar(p.X - 1, p.Y - 1) && cmap.get(p.X - 1, p.Y - 1).Organization == "main")
                {
                    targetable = true;
                    targetableChar.Add(new Point(p.X - 1, p.Y - 1));
                }
                if (cmap.isChar(p.X + 1, p.Y + 1) && cmap.get(p.X + 1, p.Y + 1).Organization == "main")
                {
                    targetable = true;
                    targetableChar.Add(new Point(p.X + 1, p.Y + 1));
                }
                if (cmap.isChar(p.X + 1, p.Y - 1) && cmap.get(p.X + 1, p.Y - 1).Organization == "main")
                {
                    targetable = true;
                    targetableChar.Add(new Point(p.X + 1, p.Y - 1));
                }
                if (cmap.isChar(p.X - 2, p.Y) && cmap.get(p.X - 2, p.Y).Organization == "main")
                {
                    targetable = true;
                    targetableChar.Add(new Point(p.X - 2, p.Y));
                }
                if (cmap.isChar(p.X, p.Y - 2) && cmap.get(p.X, p.Y - 2).Organization == "main")
                {
                    targetable = true;
                    targetableChar.Add(new Point(p.X, p.Y - 2));
                }
                if (cmap.isChar(p.X + 2, p.Y) && cmap.get(p.X + 2, p.Y).Organization == "main")
                {
                    targetable = true;
                    targetableChar.Add(new Point(p.X + 2, p.Y));
                }
                if (cmap.isChar(p.X, p.Y + 2) && cmap.get(p.X, p.Y + 2).Organization == "main")
                {
                    targetable = true;
                    targetableChar.Add(new Point(p.X, p.Y + 2));
                }
            }
            else if (c is Healer)
            {
                if (cmap.isChar(p.X - 1, p.Y) && cmap.get(p.X - 1, p.Y).Organization == "ennemy")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X - 1, p.Y));
                }
                if (cmap.isChar(p.X, p.Y - 1) && cmap.get(p.X, p.Y - 1).Organization == "ennemy")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X, p.Y - 1));
                }
                if (cmap.isChar(p.X + 1, p.Y) && cmap.get(p.X + 1, p.Y).Organization == "ennemy")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X + 1, p.Y));
                }
                if (cmap.isChar(p.X, p.Y + 1) && cmap.get(p.X, p.Y + 1).Organization == "ennemy")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X, p.Y + 1));
                }
            }
            else if (c is Caster)
            {
                if (cmap.isChar(p.X - 1, p.Y) && cmap.get(p.X - 1, p.Y).Organization == "main")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X - 1, p.Y));
                }
                if (cmap.isChar(p.X, p.Y - 1) && cmap.get(p.X, p.Y - 1).Organization == "main")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X, p.Y - 1));
                }
                if (cmap.isChar(p.X + 1, p.Y) && cmap.get(p.X + 1, p.Y).Organization == "main")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X + 1, p.Y));
                }
                if (cmap.isChar(p.X, p.Y + 1) && cmap.get(p.X, p.Y + 1).Organization == "main")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X, p.Y + 1));
                }
                if (cmap.isChar(p.X - 1, p.Y + 1) && cmap.get(p.X - 1, p.Y + 1).Organization == "main")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X - 1, p.Y + 1));
                }
                if (cmap.isChar(p.X - 1, p.Y - 1) && cmap.get(p.X - 1, p.Y - 1).Organization == "main")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X - 1, p.Y - 1));
                }
                if (cmap.isChar(p.X + 1, p.Y + 1) && cmap.get(p.X + 1, p.Y + 1).Organization == "main")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X + 1, p.Y + 1));
                }
                if (cmap.isChar(p.X + 1, p.Y - 1) && cmap.get(p.X + 1, p.Y - 1).Organization == "main")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X + 1, p.Y - 1));
                }
                if (cmap.isChar(p.X - 2, p.Y) && cmap.get(p.X - 2, p.Y).Organization == "main")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X - 2, p.Y));
                }
                if (cmap.isChar(p.X, p.Y - 2) && cmap.get(p.X, p.Y - 2).Organization == "main")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X, p.Y - 2));
                }
                if (cmap.isChar(p.X + 2, p.Y) && cmap.get(p.X + 2, p.Y).Organization == "main")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X + 2, p.Y));
                }
                if (cmap.isChar(p.X, p.Y + 2) && cmap.get(p.X, p.Y + 2).Organization == "main")
                {
                    castable = true;
                    targetableChar.Add(new Point(p.X, p.Y + 2));
                }
            }

            if (targetable)
            {
                foreach (Point pt in targetableChar)
                {
                    if (target == new Point(-1, -1) || cmap.get(pt.X, pt.Y).stats.hp < cmap.get(target.X, target.Y).stats.hp)
                        target = pt;
                }
            }

            if (castable)
            {
                foreach (Point pt in targetableChar)
                {
                    if (target == new Point(-1, -1) || cmap.get(pt.X, pt.Y).stats.hp < cmap.get(target.X, target.Y).stats.hp)
                        target = pt;
                }
            }

            return target;
        }
コード例 #3
0
ファイル: derpAI.cs プロジェクト: nlacombe42/forgottenschism
        public static Boolean battle(CharMap cmap, Tilemap tm, String org, Map map, Unit ally, Unit enemy, Label dmg, Label action, ref Boolean gameOver, ref Boolean defeat, GameTime gameTime)
        {
            Character c = cmap.get(map.CursorPosition.X, map.CursorPosition.Y);
            Character m;
            Point p;
            Point ne;

            if (c != null && c.Organization == org && c.stats.movement != 0)
            {
                if(c is Healer)
                    ne = nearest(cmap, map.CursorPosition, "ennemy");
                else
                    ne = nearest(cmap, map.CursorPosition, "main");

                if (isAdj(map.CursorPosition, ne))
                {
                    c.stats.movement = 0;
                    p = map.CursorPosition;
                }
                else
                {
                    //finds path to nearest ennemy
                    p = pathFind(cmap, tm, map.CursorPosition, nearest(cmap, map.CursorPosition, "main"), org);
                    if (c.stats.movement > 0)
                    {
                            cmap.move(map.CursorPosition.X, map.CursorPosition.Y, p.X, p.Y);
                            map.changeCursor(new Point(p.X, p.Y));
                    }
                    c.stats.movement--;
                }

                if (c.stats.movement == 0)
                {
                    Point tar = targetCharacter(c, p, cmap);

                    if (tar != new Point(-1, -1))
                    {
                        m = cmap.get(tar.X, tar.Y);
                        map.CurLs.Add(tar, Content.Graphics.Instance.Images.gui.cursorRed);

                        if (c is Fighter)
                            dmg.Text = ((Fighter)c).attack(m);
                        else if (c is Archer)
                            dmg.Text = ((Archer)c).attack(m);
                        else if (c is Scout)
                            dmg.Text = ((Scout)c).attack(m);
                        else if (c is Healer)
                        {
                            dmg.Text = ((Healer)c).heal(m).ToString();
                            action.Text = "Heal";
                        }
                        else if (c is Caster)
                        {
                            dmg.Text = ((Caster)c).attack(m, new Spell("DerpCast", 1, 5, 1, 5));
                            action.Text = "DerpCast";
                        }
                        else
                            dmg.Text = "Cant";

                        if (action.Text == "")
                            action.Text = "Attack";

                        dmg.Position = new Vector2(tar.X * 64 - map.getTlc.X * 64, tar.Y * 64 - map.getTlc.Y * 64 + 20);
                        dmg.visibleTemp(500);
                        action.visibleTemp(500);

                        if (dmg.Text != "miss" || dmg.Text != "Cant")
                        {
                            enemy.set(c.Position.X, c.Position.Y, c);
                            ally.set(m.Position.X, m.Position.Y, m);
                            if (m.stats.hp <= 0)
                            {
                                if (m.isMainChar())
                                    gameOver = true;

                                ally.delete(m.Position.X, m.Position.Y);
                                cmap.set(tar.X, tar.Y, null);
                                cmap.update(map);

                                if (ally.Characters.Count <= 0)
                                    defeat = true;
                            }
                        }
                    }
                }
                return false;
            }
            else
            {
                for (int e = cmap.NumY - 1; e >= 0; e--)
                    for (int i = cmap.NumX - 1; i >= 0; i--)
                        if (cmap.isChar(i, e) && cmap.get(i, e).stats.movement != 0 && cmap.get(i, e).Organization == org)
                        {
                            if (map.CursorPosition != new Point(i, e))
                            {
                                map.CurLs.Clear();
                                dmg.Visible = false;
                                action.Visible = false;
                                action.Text = "";
                                map.changeCursor(new Point(i, e));
                                return false;
                            }
                        }
            }

            cmap.resetAllMovement(org);
            return true;
        }