Ejemplo n.º 1
0
        /// <summary>
        /// Ngược lại, sử dụng millisecondsPerFrame từ Constructor.
        /// </summary>
        public Enemy
        (
            GameplayScreen gameplayScreen, Texture2D botTexture, Texture2D topTexture, Color color, AItype AItypeID,
            WeaponSet weaponSet, Vector2 position, float rotationAngle, Vector2 maximumSpeed,
            int hitPoints, Point frameSize, Point sheetSize, Point frameSizeTop,
            Point sheetSizeTop, int millisecondsPerFrame
        )
            : base
            (
                gameplayScreen, botTexture, topTexture, color, position, rotationAngle, maximumSpeed,
                hitPoints, frameSize, sheetSize, frameSizeTop, sheetSizeTop,
                millisecondsPerFrame
            )
        {
            this.AItypeID  = AItypeID;
            this.typeID    = 89;
            this.weaponSet = weaponSet;
            this.typeIndex = GameplayScreen.EnemyList.Count;

            AIrotate          = RotationAngle;
            AIcommingposition = CurrentMapPosition;

            CurrentMapPosition = PreviousMapPosition =
                Map.GetSquareAtPixel(CurrentWorldPosition);
            CurrentMapPositionIndex = PreviousMapPositionIndex = 1;
            Map.MapSquares
            [(int)CurrentMapPosition.X, (int)CurrentMapPosition.Y]
            [CurrentMapPositionIndex, 0] = typeID;
            Map.MapSquares
            [(int)CurrentMapPosition.X, (int)CurrentMapPosition.Y]
            [CurrentMapPositionIndex, 1] = typeIndex;
        }
Ejemplo n.º 2
0
        // Ngược lại, sử dụng custom millisecondsPerFrame
        public Enemy
        (
            Texture2D botTexture, Texture2D topTexture, Color color, AItype AItypeID,
            Vector2 position, float rotationAngle, Vector2 maximumSpeed,
            int hitPoints, Point frameSize, Point sheetSize,
            int millisecondsPerFrame
        )
            : base
            (
                botTexture, topTexture, color, position, rotationAngle, maximumSpeed,
                hitPoints, frameSize, sheetSize, millisecondsPerFrame
            )
        {
            // Test, cho Tank một movingSpeed xác định, rồi tính toán direction
            // dựa vào movingSpeed này
            movingSpeed = new Vector2(1, 0);             // Tốc độ đi tới = 1

            this.AItypeID = AItypeID;

            currentMapPosition = TileMap.GetSquareAtPixel(position);
            AIcommingposition  = new Point((int)currentMapPosition.X, (int)currentMapPosition.Y);
            AIrotate           = 0.0;
            TileMap.MapSquares[(int)currentMapPosition.X, (int)currentMapPosition.Y][2, 0] = 89;
            TileMap.MapSquares[(int)currentMapPosition.X, (int)currentMapPosition.Y][2, 1] = GameplayScreen.EnemyList.Count;
            currentMapPositionIndex = 2;
        }
Ejemplo n.º 3
0
 private int AIfireatwill = 0;                // no need: always = 0 (not need to fire)
 //adder
 #region Constructors
 // Nếu ko truyền vào tham số millisecondsPerFrame
 // Sử dụng defaultMillisecondsPerFrame = 16 (mặc định)
 public Enemy
 (
     Texture2D botTexture, Texture2D topTexture, Color color, AItype AItypeID,
     Vector2 position, float rotationAngle, Vector2 maximumSpeed,
     int hitPoints, Point frameSize, Point sheetSize
 )
     : this
     (
         botTexture, topTexture, color, AItypeID, position, rotationAngle, maximumSpeed,
         hitPoints, frameSize, sheetSize, defaultMillisecondsPerFrame
     )
 {
 }
Ejemplo n.º 4
0
 /// <summary>
 /// finds a target of specific type 
 /// then it moves toward it until it is close enought
 /// fails if no units in detection range
 /// </summary>
 /// <param name="agent"></param>
 /// <param name="_range"></param>
 /// <param name="ArriveRadius"></param>
 /// <param name="_type"></param>
 public Node_Seek_Modular(IMoveToNode MoveNode, float _range, float ArriveRadius, AItype _type = AItype.none)
 {
     m_range = _range;
     m_child1 = MoveNode;
     m_child2 = new Node_FindClosestTarget(m_range, _type);
     m_child1.SetArriveRadius(ArriveRadius);
 }
Ejemplo n.º 5
0
 public Node_Find_Closest_Target_BB(Dictionary<string, System.Object> blackBoard, string bb_key, float radius, AItype type = AItype.none)
 {
     m_radius = radius;
     m_typeToLookFor = type;
     m_dict = blackBoard;
     m_key = bb_key;
 }
Ejemplo n.º 6
0
    public List <Foe> readFoes(GameProgress.jankFile input)
    {
        // Determine number of unique foes
        string s = input.ReadLine();

        string[] split  = s.Split(' ');
        int      foeAmt = 0;

        int.TryParse(split[split.Length - 1], out foeAmt);

        // Read in each foe in the ecosystem
        Foe[] community = new Foe[foeAmt];
        for (int i = 0; i < foeAmt; i++)
        {
            input.ReadLine();
            input.ReadLine();
            string       foeName   = "";
            string       path      = "";
            int[]        stats     = new int[7];
            List <Skill> skillList = new List <Skill>();

            // Read in name
            s     = input.ReadLine();
            split = s.Split(' ');
            for (int j = 1; j < split.Length; j++)
            {
                foeName += split[j];
                if (j != split.Length - 1)
                {
                    foeName += " ";
                }
            }
            // Read in path
            path = input.ReadLine();
            // Read in stats
            s     = input.ReadLine();
            split = s.Split(' ');
            for (int j = 1; j < split.Length; j++)
            {
                int.TryParse(split[j], out stats[j - 1]);
            }
            // Open up the sprites in the path file
            Sprite[] source = Resources.LoadAll <Sprite>(@path);

            // Read in items
            int itemAmt;
            s     = input.ReadLine();
            split = s.Split(' ');
            int.TryParse(split[split.Length - 1], out itemAmt);
            Item[] drops    = new Item[itemAmt];
            int[]  dropRate = new int[itemAmt];

            for (int j = 0; j < itemAmt; j++)
            {
                int itemID, itemCount, itemOdds;
                s     = input.ReadLine();
                split = s.Split(' ');
                int.TryParse(split[0], out itemID);
                int.TryParse(split[1], out itemCount);
                int.TryParse(split[2], out itemOdds);

                Item theDrop = (Item)TitleManager.curFile.getItemList()[itemID];
                drops[j]    = theDrop.copy(itemCount);
                dropRate[j] = itemOdds;
            }

            // Read in skills
            int skillAmt;
            s     = input.ReadLine();
            split = s.Split(' ');
            int.TryParse(split[split.Length - 1], out skillAmt);

            int[]    skillOdds = new int[skillAmt];
            AItype[] ai        = new AItype[skillAmt];
            for (int j = 0; j < skillAmt; j++)
            {
                skillType       skill;
                string          atkName, des, skillSFX;
                element         atkEle;
                int             basePower, mpCost, range, effectChance;
                bool            isMagical, animLoop;
                float           start, end, fps;
                SpriteAnimation anim;

                battleType support    = battleType.NULL;
                status     statusMod  = status.NULL;
                int        scalar     = 0;
                stat       statBoost  = stat.NULL;
                bool       selfTarget = false;
                bool       targetAlly = false;

                s       = input.ReadLine();
                split   = s.Split('-');
                atkName = split[1];
                des     = input.ReadLine();

                // Read in odds then ai type
                s     = input.ReadLine();
                split = s.Split(' ');
                int.TryParse(split[split.Length - 1], out skillOdds[j]);
                s     = input.ReadLine();
                split = s.Split(' ');
                ai[j] = decideAI(split[split.Length - 1]);

                s     = input.ReadLine();
                split = s.Split(' ');
                if (split[split.Length - 1].CompareTo("Offensive") == 0)
                {
                    skill = skillType.OFFENSIVE;

                    // Attack element
                    s      = input.ReadLine();
                    split  = s.Split(' ');
                    atkEle = decideEle(split[split.Length - 1]);

                    // base power
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    int.TryParse(split[split.Length - 1], out basePower);

                    // mp cost
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    int.TryParse(split[split.Length - 1], out mpCost);

                    // is magical
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    bool.TryParse(split[split.Length - 1], out isMagical);

                    // effect chance
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    int.TryParse(split[split.Length - 1], out effectChance);
                    if (effectChance > 0)
                    {
                        /*
                         * implement me eventually
                         */
                    }

                    // range
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    int.TryParse(split[split.Length - 1], out range);

                    // positions
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    float.TryParse(split[split.Length - 1], out start);
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    float.TryParse(split[split.Length - 1], out end);

                    // FPS
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    float.TryParse(split[split.Length - 1], out fps);

                    // Sprite animation
                    int spriteAmt;
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    if (split.Length > 2)
                    {
                        int.TryParse(split[split.Length - 2], out spriteAmt);
                        animLoop = true;
                    }
                    else
                    {
                        int.TryParse(split[split.Length - 1], out spriteAmt);
                        animLoop = false;
                    }
                    Sprite[] sprites = new Sprite[spriteAmt];
                    for (int k = 0; k < spriteAmt; k++)
                    {
                        s          = input.ReadLine();
                        sprites[k] = getSprite(source, s);
                    }
                    anim = new SpriteAnimation(sprites, new int[0], fps, animLoop);
                }
                else
                {
                    skill        = skillType.SUPPORT;
                    basePower    = 0;
                    effectChance = 0;
                    isMagical    = true;

                    // Attack element
                    s      = input.ReadLine();
                    split  = s.Split(' ');
                    atkEle = decideEle(split[split.Length - 1]);

                    // mp cost
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    int.TryParse(split[split.Length - 1], out mpCost);

                    // range
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    int.TryParse(split[split.Length - 1], out range);

                    // positions
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    float.TryParse(split[split.Length - 1], out start);
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    float.TryParse(split[split.Length - 1], out end);

                    // status variables
                    s         = input.ReadLine();
                    split     = s.Split(' ');
                    support   = decideSupport(split[split.Length - 1]);
                    s         = input.ReadLine();
                    split     = s.Split(' ');
                    statusMod = decideStatus(split[split.Length - 1]);
                    s         = input.ReadLine();
                    split     = s.Split(' ');
                    statBoost = decideStat(split[split.Length - 1]);
                    s         = input.ReadLine();
                    split     = s.Split(' ');
                    int.TryParse(split[split.Length - 1], out scalar);
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    bool.TryParse(split[split.Length - 1], out selfTarget);
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    bool.TryParse(split[split.Length - 1], out targetAlly);

                    // FPS
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    float.TryParse(split[split.Length - 1], out fps);

                    // Sprite animation
                    int spriteAmt;
                    s     = input.ReadLine();
                    split = s.Split(' ');
                    if (split.Length > 2)
                    {
                        int.TryParse(split[split.Length - 2], out spriteAmt);
                        animLoop = true;
                    }
                    else
                    {
                        int.TryParse(split[split.Length - 1], out spriteAmt);
                        animLoop = false;
                    }
                    Sprite[] sprites = new Sprite[spriteAmt];
                    for (int k = 0; k < spriteAmt; k++)
                    {
                        s          = input.ReadLine();
                        sprites[k] = getSprite(source, s);
                    }
                    anim = new SpriteAnimation(sprites, new int[0], fps, animLoop);
                }
                // Get SFX path
                input.ReadLine();
                skillSFX = input.ReadLine();

                Skill move = new Skill(skill, atkName, des, atkEle, mpCost, range, start, end, anim, skillSFX);
                move.setAttack(basePower, isMagical, effectChance);
                if (skill == skillType.SUPPORT)
                {
                    move.setSupport(support, statusMod, statBoost, scalar, selfTarget, targetAlly);
                }
                skillList.Add(move);
            }
            // Hitboxes
            int hitboxAmt;
            s     = input.ReadLine();
            split = s.Split(' ');
            int.TryParse(split[split.Length - 1], out hitboxAmt);
            HitBox[] boxes = new HitBox[hitboxAmt];
            for (int j = 0; j < hitboxAmt; j++)
            {
                s     = input.ReadLine();
                split = s.Split(' ');
                float x, y, xs, ys;
                float.TryParse(split[0], out x);
                float.TryParse(split[1], out y);
                float.TryParse(split[2], out xs);
                float.TryParse(split[3], out ys);

                boxes[j] = new HitBox((x / 2) + xs, (y / 2) + ys, (-x / 2) + xs, (-y / 2) + ys);
            }
            // Gravity
            float gravity;
            s     = input.ReadLine();
            split = s.Split(' ');
            float.TryParse(split[split.Length - 1], out gravity);

            // Read in standard animations
            input.ReadLine();
            input.ReadLine();
            string facePath = input.ReadLine();
            Sprite face     = getSprite(Resources.LoadAll <Sprite>(@facePath), input.ReadLine());
            List <SpriteAnimation> anims = new List <SpriteAnimation>();
            for (int j = 0; j < 5; j++)
            {
                input.ReadLine();
                // FPS
                float fps;
                s     = input.ReadLine();
                split = s.Split(' ');
                float.TryParse(split[split.Length - 1], out fps);

                // Sprite animation
                int spriteAmt;
                s     = input.ReadLine();
                split = s.Split(' ');
                int.TryParse(split[split.Length - 1], out spriteAmt);

                Sprite[] sprites = new Sprite[spriteAmt];
                for (int k = 0; k < spriteAmt; k++)
                {
                    s          = input.ReadLine();
                    sprites[k] = getSprite(source, s);
                }
                SpriteAnimation anim = new SpriteAnimation(sprites, new int[0], fps, true);
                anims.Add(anim);
            }

            Foe inhabitant = new Foe(foeName, stats, skillList, skillOdds, ai, drops, dropRate, boxes, gravity);
            inhabitant.setAnimations(face, anims[0], anims[1], anims[2], anims[3], anims[4]);
            community[i] = inhabitant;
        }

        // Create an empty foe set so you don't have to use NULL
        int[] nothing = { 0, 0, 0, 0, 0, 0, 0 };
        Foe   empty   = new Foe("", nothing, new List <Skill>(), new int[0], new AItype[0], new Item[0], new int[0], new HitBox[0], 0);

        // Read in sets of enemies
        input.ReadLine();
        int setAmt;

        s     = input.ReadLine();
        split = s.Split(' ');
        int.TryParse(split[split.Length - 1], out setAmt);
        List <Foe> foeList = new List <Foe>();

        for (int j = 0; j < 1; j++)
        {
            input.ReadLine();
            // Read in rate
            s = input.ReadLine();
            // Read in foes
            int foeCount;
            s     = input.ReadLine();
            split = s.Split(' ');
            int.TryParse(split[split.Length - 1], out foeCount);
            for (int k = 0; k < 5; k++)
            {
                if (k < foeCount)
                {
                    int foeNum;
                    s = input.ReadLine();
                    int.TryParse(s, out foeNum);
                    foeList.Add(community[foeNum]);
                }
                else
                {
                    foeList.Add(empty);
                }
            }
        }
        return(foeList);
    }
 /// <summary>
 /// finds the closest target and turns toward it 
 /// fails if it cant find a target
 /// </summary>
 /// <param name="agent"></param>
 /// <param name="_range"></param>
 /// <param name="ArriveRadius"></param>
 /// <param name="_type"></param>
 public Node_AlignToTarget(UnityEngine.AI.NavMeshAgent agent, float _range, float ArriveRadius, AItype _type = AItype.none, float TurnSpeed = 3)
 {
     m_child1 = new Node_FindClosestTarget(_range, _type);
     m_child2 = new Node_Align(TurnSpeed);
 }
 /// <summary>
 /// finds a target of specific type 
 /// then it moves toward it until it is close enought
 /// fails if no units in detection range
 /// </summary>
 /// <param name="agent"></param>
 /// <param name="_range"></param>
 /// <param name="ArriveRadius"></param>
 /// <param name="_type"></param>
 public Node_Seek(UnityEngine.AI.NavMeshAgent agent, float _range, float ArriveRadius, AItype _type = AItype.none)
 {
     m_range = _range;
     m_child1 = new Node_MoveTo_With_Avoid(agent);
     m_child2 = new Node_FindClosestTarget(m_range, _type);
     m_child1.SetArriveRadius(ArriveRadius);
 }
 public Node_FindClosestTarget(float radius, AItype type = AItype.none)
 {
     m_radius = radius;
     m_typeToLookFor = type;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Nếu ko truyền vào tham số millisecondsPerFrame thì sử dụng
 /// defaultMillisecondsPerFrame = 16 (mặc định)
 /// </summary>
 public Enemy
 (
     GameplayScreen gameplayScreen, Texture2D botTexture, Texture2D topTexture, Color color, AItype AItypeID,
     WeaponSet weaponSet, Vector2 position, float rotationAngle, Vector2 maximumSpeed,
     int hitPoints, Point frameSize, Point sheetSize, Point frameSizeTop,
     Point sheetSizeTop
 )
     : this
     (
         gameplayScreen, botTexture, topTexture, color, AItypeID, weaponSet, position, rotationAngle, maximumSpeed,
         hitPoints, frameSize, sheetSize, frameSizeTop, sheetSizeTop,
         defaultMillisecondsPerFrame
     )
 {
 }