Esempio n. 1
0
    protected virtual void ChooseNextAction()
    {
        Surroundings surroundings = Environment.Sense(coord);

        if (surroundings.nearestFoodSource != null)
        {
            currentAction = CreatureAction.GoingToFood;
            foodTarget    = surroundings.nearestFoodSource;
        }

        // If exploring, move to random tile
        if (currentAction == CreatureAction.Exploring)
        {
            StartMoveToCoord(Environment.GetNextTileWeighted(coord, moveFromCoord));
        }
        else if (currentAction == CreatureAction.GoingToFood)
        {
            if (Coord.AreNeighbours(coord, foodTarget.coord))
            {
                currentAction = CreatureAction.Eating;
            }
            else
            {
                StartMoveToCoord(EnvironmentUtility.GetNextInPath(coord.x, coord.y, foodTarget.coord.x, foodTarget.coord.y));
            }
        }
    }
Esempio n. 2
0
    public Surroundings expandByAP(int maxAp)
    {
        Surroundings surroundings = new Surroundings(this);

        this.expandRecursiveByAP(0, 0, maxAp, surroundings);
        return(surroundings);
    }
Esempio n. 3
0
    public Surroundings expandByDistance(int maxDist)
    {
        Surroundings surroundings = new Surroundings(this);

        this.expandRecursiveByDistance(0, 0, maxDist, surroundings);
        return(surroundings);
    }
Esempio n. 4
0
 private void expandRecursiveByAP(int dist, int AP, int maxAP, Surroundings surroundings, bool isUndeadHorse = false)
 {
     if (AP > maxAP)
     {
         return;
     }
     if (!surroundings.addOrUpdateTerrainForSmallerValues(this, x, y, dist, AP))
     {
         return;
     }
     if (creature != null && dist != 0 && !isUndeadHorse)
     {
         return;
     }
     for (int aux = 0; aux < this.neighboursCount; aux++)
     {
         if (this.neighbours[aux].movePointsRequired != -1 || isUndeadHorse)
         {
             neighbours[aux].expandRecursiveByAP(
                 dist + 1,
                 AP + (movePointsRequired == -1? 1 : movePointsRequired),
                 maxAP,
                 surroundings,
                 dist == 0 && creature is UndeadKnight? true: isUndeadHorse
                 );
         }
     }
 }
    public virtual Surroundings mouseDown()
    {
        Surroundings surroundings = terrain.expandByAP(this.actionPoints);

        surroundings.paint(Color.red);
        return(surroundings);
    }
 //public Surroundings previewTrap(){
 public void previewTrap(){
    if(!skills[0].canUse()) return;
    GameController.console.Log("Previewing trap\n");
    preview = terrain.expandByDistance(terrain.movePointsRequired);
    GameController.overrideClick(trySetTrap);
    preview.paint(Color.blue);
 }
    public void lastResource()
    {
        if (!skills[2].use())
        {
            return;
        }
        Surroundings surroundings = terrain.expandByDistance(1);

        lastResourcesTargets = new List <Pair <Creature, int> >();
        GameController.console.Log("using last resource\n");
        for (int aux = 0; aux < surroundings.creatures.Count; aux++)
        {
            Creature creature = surroundings.creatures[aux].second;
            if (creature == this)
            {
                continue;
            }
            if (creature.team == team)
            {
                int ammount = (int)((float)(creature.maxHealth - creature.health) * 1.5);
                creature.defenseResistance += ammount;
                lastResourcesTargets.Add(new Pair <Creature, int>(creature, ammount));
                GameController.console.Log("giving " + ammount + " defense to + " + creature.getName() + "\n");
            }
        }
    }
Esempio n. 8
0
 private static void selectCreature(Creature creature)
 {
     if (possibilities != null)
     {
         clearAll();
     }
     creatureClicked = creature;
     if (creature != null)
     {
         GameObject.FindGameObjectWithTag("SoundController").GetComponent <Sound_controller>().playClick();
         int ap    = creature.actionPoints;
         int range = creature.attackRange;
         if (creature is HumanKnight && creature.terrain is Plains && creature.actionPoints > 0)
         {
             ap++;
         }
         if (creature is HumanSiege)
         {
             if ((creature as HumanSiege).isMounted)
             {
                 ap = 0;
             }
             else
             {
                 range = 0;
             }
         }
         if (creature is UndeadSiege)
         {
             if ((creature as UndeadSiege).isMounted)
             {
                 ap = 0;
             }
             else
             {
                 range = 0;
             }
         }
         possibilities = creature.terrain.expandByAP(ap);
         possibilities.paint(Color.red);
         attackPossibilities = creature.terrain.expandByDistance(range);
         for (int aux = 0; aux < attackPossibilities.creatures.Count; aux++)
         {
             Creature targetCreature = attackPossibilities.creatures[aux].second;
             if (targetCreature.team != creature.team)
             {
                 targetCreature.terrain.setColor(Color.blue);
             }
         }
     }
     else
     {
         possibilities       = null;
         attackPossibilities = null;
     }
     guiController.selectCreature(creature);
 }
Esempio n. 9
0
 // Start is called before the first frame update
 void Start()
 {
     rb   = GetComponent <Rigidbody>();
     surr = transform.GetChild(0).gameObject.GetComponent <Surroundings>();
     SetUpEvent(OnHit);
     SetUpEvent(OnFlip);
     Flip();
     StartCoroutine(ResetJump());
 }
Esempio n. 10
0
    void Start()
    {
        JumpsAmountLeft = JumpsAmount;
        RB = GetComponent <Rigidbody2D>();
        SR = GetComponent <Surroundings>();

        //WallHopDirection.Normalize();
        //WallJumpDirection.Normalize();
    }
Esempio n. 11
0
 // Use this for initialization
 void Start()
 {
     facing       = GetComponent <Facing> ();
     rb           = GetComponent <Rigidbody2D> ();
     pulse        = GetComponent <Pulse> ();
     surroundings = GetComponent <Surroundings> ();
     jump         = GetComponent <Jump> ();
     jetpack      = GetComponent <Jetpack> ();
     playerInfo   = GetComponent <Player> ();
 }
 public void previewPossess()
 {
     if (!skills[1].canUse())
     {
         return;
     }
     possessSurroundings = terrain.expandByDistance(3);
     GameController.overrideClick(tryPossess);
     possessSurroundings.paint(Color.blue);
 }
Esempio n. 13
0
 public void previewCursedTouch()
 {
     if (!skills[0].canUse())
     {
         return;
     }
     cursedTouchSurroundings = terrain.expandByDistance(1);
     GameController.overrideClick(this.tryCursedTouch);
     cursedTouchSurroundings.paint(Color.blue);
 }
Esempio n. 14
0
 public void previewCorner()
 {
     if (!skills[1].canUse())
     {
         return;
     }
     cornerSurroundings = terrain.expandByDistance(2);
     GameController.overrideClick(tryCorner);
     cornerSurroundings.paint(Color.blue);
 }
Esempio n. 15
0
    public static Surroundings Sense(Coord coord)
    {
        var closestPlant = speciesMaps[Species.Plant].ClosestEntity(coord, Animal.maxViewDistance);
        var surroundings = new Surroundings();

        surroundings.nearestFoodSource = closestPlant;
        surroundings.nearestWaterTile  = closestVisibleWaterMap[coord.x, coord.y];

        return(surroundings);
    }
 public void previewSupress()
 {
     if (!skills[2].canUse())
     {
         return;
     }
     supressSurroundings = terrain.expandByDistance(2);
     GameController.overrideClick(trySupress);
     supressSurroundings.paint(Color.blue);
 }
 public void previewRevive()
 {
     if (!skills[1].canUse())
     {
         return;
     }
     reviveSurroundings = terrain.expandByDistance(1);
     GameController.overrideClick(tryRevive);
     reviveSurroundings.paint(Color.blue);
 }
Esempio n. 18
0
    //takes the pieces action and coordinates and returns if the piece is able to take that action
    bool IsLegal(ref ActionType action, int posX, int posZ)
    {
        Surroundings surr      = GetSurroundings(posX, posZ);
        int          direction = (int)action;

        if (surr.array[direction] != PieceType.INACCESSIBLE)
        {
            return(true);
        }
        return(false);
    }
Esempio n. 19
0
    public override bool defend()
    {
        if (!base.defend())
        {
            return(false);
        }
        Surroundings surroundings = terrain.expandByDistance(_areaHealingRange);

        for (int aux = 1; aux < surroundings.creatures.Count; aux++)
        {
            surroundings.creatures[aux].second.changeHealth(_areaHealingAmmount);
        }
        return(true);
    }
Esempio n. 20
0
 private static void selectCreature(Creature creature)
 {
     if (possibilities != null)
     {
         creatureClicked.mouseUp(possibilities);
     }
     creatureClicked = creature;
     if (creature != null)
     {
         possibilities = creatureClicked.mouseDown();
     }
     else
     {
         possibilities = null;
     }
 }
Esempio n. 21
0
    public void habilityPush()
    {
        if (!skills[2].use())
        {
            return;
        }
        GameController.console.Log("Pushed!\n");

        Surroundings surroundings = terrain.expandByDistance(_pushRange);

        for (int aux = 1; aux < surroundings.creatures.Count; aux++)
        {
            habilityPushAux(surroundings.creatures[aux].second);
        }
        return;
    }
Esempio n. 22
0
    public Trap(GameObject prefab, int x, int y, int team, int lifeSpam = 15, int activationRange = 0)
    {
        this.x               = x;
        this.y               = y;
        this.team            = team;
        this.lifeSpam        = lifeSpam;
        this.activationRange = activationRange;

        terrain        = Terrain.allTiles[y][x];
        terrain.trap   = this;
        spriteInstance = MonoBehaviour.Instantiate(prefab);
        spriteInstance.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
        spriteInstance.transform.position   = terrain.spriteInstance.transform.position + new Vector3(0, 0, -0.0001f);
        surroundings = terrain.expandByDistance(activationRange);
        allTraps.Add(this);
    }
 public void trySetTrap(Terrain terrain)
 {
     if (preview.hasTerrain(terrain.x, terrain.y))
     {
         if (terrain.creature == null && terrain.trap == null)
         {
             if (!(terrain is Mountain))
             {
                 this.setTrap(terrain.x, terrain.y);
             }
             else GameController.console.Log("Cant place trap in mountain\n");
         }
         else GameController.console.Log("Cant place trap over another creature or trap\n");
     }
     else GameController.console.Log("position out of range\n");
     preview.clear();
     preview = null;
 }
Esempio n. 24
0
    public override Surroundings mouseDown()
    {
        Surroundings surroundings = base.mouseDown();

        if (movedLastTurn)
        {
            return(surroundings);
        }

        foreach (var item in surroundings.creatures)
        {
            if (item.first == _attackRange + 1)
            {
                enemiesInTheBorder.Add(item.second);
            }
        }
        return(surroundings);
    }
Esempio n. 25
0
        void updateSurroundingsAndNormals(Map map)
        {
            Point origin = new Point(Entity.Position.X, Entity.Position.Y);

            float[] surroundingTilesZ = new float[kSurroundingsIndexes.Length];


            for (int i = 0; i < kSurroundingsIndexes.Length; i++)
            {
                surroundingTilesZ[i] = map.GetTileZ(origin.X + kSurroundingsIndexes[i].X, origin.Y + kSurroundingsIndexes[i].Y);
            }

            m_SurroundingTiles = new Surroundings(
                surroundingTilesZ[7], surroundingTilesZ[3], surroundingTilesZ[6]);

            bool isFlat = m_SurroundingTiles.IsFlat && m_SurroundingTiles.East == Entity.Z;

            if (!isFlat)
            {
                int low = 0, high = 0, sort = 0;
                sort = map.GetAverageZ(Entity.Z, (int)m_SurroundingTiles.South, (int)m_SurroundingTiles.East, (int)m_SurroundingTiles.Down, ref low, ref high);
                if (sort != SortZ)
                {
                    SortZ = sort;
                    map.GetMapTile(Entity.Position.X, Entity.Position.Y).ForceSort();
                }
            }

            m_Normals[0] = calculateNormal(
                surroundingTilesZ[2], surroundingTilesZ[3],
                surroundingTilesZ[0], surroundingTilesZ[6]);
            m_Normals[1] = calculateNormal(
                Entity.Z, surroundingTilesZ[4],
                surroundingTilesZ[1], surroundingTilesZ[7]);
            m_Normals[2] = calculateNormal(
                surroundingTilesZ[5], surroundingTilesZ[7],
                Entity.Z, surroundingTilesZ[9]);
            m_Normals[3] = calculateNormal(
                surroundingTilesZ[6], surroundingTilesZ[8],
                surroundingTilesZ[3], surroundingTilesZ[10]);

            updateVertexBuffer();
        }
Esempio n. 26
0
 private void expandRecursiveByDistance(int dist, int AP, int maxDist, Surroundings surroundings)
 {
     if (dist > maxDist)
     {
         return;
     }
     if (!surroundings.addOrUpdateTerrainForSmallerValues(this, x, y, dist, AP))
     {
         return;
     }
     for (int aux = 0; aux < this.neighboursCount; aux++)
     {
         if (this.neighbours[aux].movePointsRequired != -1)
         {
             neighbours[aux].expandRecursiveByDistance(
                 dist + 1, AP + movePointsRequired, maxDist, surroundings
                 );
         }
     }
 }
 public void tryPossess2(Terrain terrain)
 {
     possessSurroundings.clear();
     if (!possessSurroundings.hasTerrain(terrain.x, terrain.y))
     {
         GameController.console.Log("out of range\n");
         return;
     }
     if (terrain.creature != null)
     {
         GameController.console.Log("invalid target\n");
         return;
     }
     if (!skills[1].use(terrain.creature))
     {
         return;
     }
     possessSurroundings.origin.creature.setPos(terrain.x, terrain.y);
     possessSurroundings = null;
 }
Esempio n. 28
0
    //takes the pieces surroundings and returns the pieces intended direction
    public override ActionType TakeTurn(Surroundings surr)
    {
        //lists holding the pieces surrounding resources or empty spaces
        List <int> resourcePositions = new List <int>();
        List <int> emptyPositions    = new List <int>();
        //the piece will stay in its current location if no direction is viable
        int emptySpace = 4;

        //fills the lists with the index of each respective surrounding
        for (int i = 0; i < 9; i++)
        {
            if (surr.array[i] == PieceType.FOOD || surr.array[i] == PieceType.ADVANTAGE)
            {
                resourcePositions.Add(i);
            }
            else if (surr.array[i] == PieceType.EMPTY)
            {
                emptyPositions.Add(i);
            }
        }
        //if there are resources nearby the piece will go towards one of them randomly
        //otherwise it will go to a random empty space
        //if neither of those options are viable it will stay in its current location
        int randNum;

        if (resourcePositions.Count > 0)
        {
            randNum    = Random.Range(0, resourcePositions.Count);
            emptySpace = resourcePositions[randNum];
        }
        else if (emptyPositions.Count > 0)
        {
            randNum    = Random.Range(0, emptyPositions.Count);
            emptySpace = emptyPositions[randNum];
        }

        return((ActionType)emptySpace);
    }
    public bool habilityPush()
    {
        if (pushCD > 0)
        {
            Debug.Log("wait " + pushCD + " turns to use this hability");
            return(false);
        }
        if (!useActionPoints(_pushAPCost))
        {
            Debug.Log("not enough action points");
            return(false);
        }
        pushCD = _pushMaxCD;
        Debug.Log("Pushed!");

        Surroundings surroundings = terrain.expandByDistance(_pushRange);

        for (int aux = 1; aux < surroundings.creatures.Count; aux++)
        {
            habilityPushAux(surroundings.creatures[aux].second);
        }
        return(true);
    }
    public void tryPossess(Terrain terrain)
    {
        possessSurroundings.clear();

        if (!possessSurroundings.hasTerrain(terrain.x, terrain.y))
        {
            Debug.Log("out of range");
            return;
        }
        if (terrain.creature == null)
        {
            GameController.console.Log("invalid target\n");
            return;
        }
        if (terrain.creature is UndeadKnight && (terrain.creature as UndeadKnight).isImmaterial)
        {
            GameController.console.Log("Cannot use habilities on immaterial undead knight");
            return;
        }
        GameController.overrideClick(tryPossess2);
        possessSurroundings = terrain.expandByDistance(3);
        possessSurroundings.paint(Color.blue);
    }
Esempio n. 31
0
        private void updateSurroundingsAndNormals(Map map)
        {
            Point origin = new Point(Entity.Position.X, Entity.Position.Y);

            float[] surroundingTilesZ = new float[kSurroundingsIndexes.Length];


            for (int i = 0; i < kSurroundingsIndexes.Length; i++)
                surroundingTilesZ[i] = map.GetTileZ(origin.X + kSurroundingsIndexes[i].X, origin.Y + kSurroundingsIndexes[i].Y);

            m_SurroundingTiles = new Surroundings(
                surroundingTilesZ[7], surroundingTilesZ[3], surroundingTilesZ[6]);

            bool isFlat = m_SurroundingTiles.IsFlat && m_SurroundingTiles.East == Entity.Z;
            if (!isFlat)
            {
                int low = 0, high = 0, sort = 0;
                sort = map.GetAverageZ((int)Entity.Z, (int)m_SurroundingTiles.South, (int)m_SurroundingTiles.East, (int)m_SurroundingTiles.Down, ref low, ref high);
                if (sort != SortZ)
                {
                    SortZ = sort;
                    map.GetMapTile(Entity.Position.X, Entity.Position.Y).ForceSort();
                }
            }

            m_Normals[0] = calculateNormal(
                surroundingTilesZ[2], surroundingTilesZ[3],
                surroundingTilesZ[0], surroundingTilesZ[6]);
            m_Normals[1] = calculateNormal(
                Entity.Z, surroundingTilesZ[4],
                surroundingTilesZ[1], surroundingTilesZ[7]);
            m_Normals[2] = calculateNormal(
                surroundingTilesZ[5], surroundingTilesZ[7],
                Entity.Z, surroundingTilesZ[9]);
            m_Normals[3] = calculateNormal(
                surroundingTilesZ[6], surroundingTilesZ[8],
                surroundingTilesZ[3], surroundingTilesZ[10]);

            updateVertexBuffer();
        }