public void setCharacterPanelVisibility(bool value, unitScript unit = null, bool targetLeft = true)
 {
     if (value && unit)
     {
         loadCharacter(unit, unit.getOwner() == 0);
     }
     if (unit && unit.getOwner() == 0)
     {
         transform.FindChild("CharacterPanel").gameObject.SetActive(value);
     }
     if (!value && targetLeft)
     {
         transform.FindChild("CharacterPanel").gameObject.SetActive(false);
     }
     if (unit)
     {
         transform.FindChild(unit.getOwner() == 0 ? "StatPanel" : "EnemyStatPanel").gameObject.SetActive(value);
         transform.FindChild(unit.getOwner() == 0 ? "WeaponPanel" : "EnemyWeaponPanel").gameObject.SetActive(value);
     }
     else
     {
         transform.FindChild(targetLeft ? "StatPanel" : "EnemyStatPanel").gameObject.SetActive(value);
         transform.FindChild(targetLeft ? "WeaponPanel" : "EnemyWeaponPanel").gameObject.SetActive(value);
     }
 }
示例#2
0
    protected float getCoverPenalty(unitScript unit, unitScript clickedUnit, float distance)
    {
        Vector2 unitPosition  = unit.GetComponent <GridItem>().getPos();
        Vector2 enemyPosition = clickedUnit.GetComponent <GridItem>().getPos();

        return(getCoverPenalty(new Vector3(unitPosition.x, 1, unitPosition.y), new Vector3(enemyPosition.x, 1.0f, enemyPosition.y)));
    }
    public void loadWeaponData(unitScript u, bool ally)
    {
        var WeaponPanel = transform.FindChild(ally?"WeaponPanel":"EnemyWeaponPanel");

        WeaponPanel.gameObject.SetActive(true);
        var weapon = u.getCurrentWeapon();

        WeaponPanel.transform.Find("Weapon").GetComponent <Text>().text = weapon.name;
        WeaponPanel.transform.Find("Damage").GetComponent <Text>().text = weapon.damage.ToString();

        var rangedPanel = WeaponPanel.transform.Find("Ranged");

        switch (weapon.type)
        {
        case WeaponType.ranged:
            rangedPanel.gameObject.SetActive(true);
            RangedWeapon current = (RangedWeapon)weapon;

            rangedPanel.Find("ShortRange").GetComponent <Text>().text = current.minRange.ToString();
            rangedPanel.Find("LongRange").GetComponent <Text>().text  = current.maxRange.ToString();

            break;

        default:
            rangedPanel.gameObject.SetActive(false);
            break;
        }
    }
示例#4
0
    protected float meleeChanceToHit(unitScript unit, unitScript clickedUnit)
    {
        if (unit.getCurrentWeapon().type == WeaponType.ranged)
        {
            return(0);
        }

        // Check outflank bonus
        int     flankBonus    = 0;  // Flank Check
        Vector2 enemyPosition = clickedUnit.GetComponent <GridItem>().getPos();

        foreach (unitScript u in playerUnitList)
        {
            if (u != null)
            {
                Vector2 unitPosition = u.GetComponent <GridItem>().getPos();
                if (u.getOwner() == controllerID && u != unit && Vector2.Distance(unitPosition, enemyPosition) < 2)
                {
                    flankBonus = 2;
                    print("Flanked Bitches");
                }
            }
        }


        // return chance to hit
        return((5.0f + (unit.getSkill() + flankBonus) - clickedUnit.getSkill()) / 10.0f);
    }
示例#5
0
    public override void spawnTeam()
    {
        controllerID = 1;
        List <unitScript> team = new List <unitScript>();

        EnemyType[] types = map.getEnemyTypes();
        Dictionary <Vector2, int> spawnData = map.getSpawnData();

        foreach (Vector2 position in spawnData.Keys)
        {
            if (spawnData[position] >= 2)            // If greater than 2 then spawn enemy
            {
                EnemyType type = types[spawnData[position]];

                GameObject newUnit = (GameObject)Instantiate(Resources.Load(type.source), transform, true);
                unitScript unit    = newUnit.GetComponent <unitScript>();

                unit.setData(type.unitName, type.unitClass, type.health, type.speed, type.skill, type.strength, type.smarts, "", new List <string>(type.weapons));
                unit.gameObject.layer = 8;
                unit.setPosition((int)position.x, (int)position.y);
                unit.setOwner(1);
                AIUnitController ai = unit.gameObject.AddComponent <AIUnitController>();
                ai.healthThreshold = type.healthThreshold;
                team.Add(unit);
                unitsInGame.Add(unit);
            }
        }
        playerUnitList = team.ToArray();
    }
    void DeselectCurrent()
    {
        //Deselect current unit
        if (selected)
        {
            unitScript unit = selected.GetComponent <unitScript>();

            if (unit != null && unit.getOwner() == 0)
            {
                gui.GetComponent <GUIController>().setCharacterPanelVisibility(false);
                gui.GetComponent <GUIController>().setCombatPanelVisibility(false);

                unit.SendMessage("deselect");

                if (unit.getOwner() == 0)
                {
                    GridItem pos = selected.GetComponent <GridItem>();
                    map.UnHilightMap();
                    //map.toggleHighlight(false,Color.white, pos.getX(), pos.getY(), unit.getSpeed());
                    pathFinder.setPathfinding(false);
                    rangeRenderer.enabled = false;
                    attackMode            = false;
                }
            }
        }

        selected = null;
    }
    public void selectUnit(unitScript unit)
    {
        GUIController cont = gui.GetComponent <GUIController>();

        DeselectCurrent();
        selected = unit.gameObject;

        cont.setCharacterPanelVisibility(true, unit);

        if (unit.getOwner() == 0)
        {
            unit.SendMessage("select");
            // IF unit has not moved
            if (unit != null && !unit.hasMoved())
            {
                // Allow them to

                if (unit.getOwner() == 0 && unit.hasMoved() == false)
                {
                    GridItem pos = selected.GetComponent <GridItem>();

                    pathFinder.getMovementPaths(pos.getPos(), unit.getMovementDistance(), true);
                    //map.toggleHighlight(true, Color.cyan, pos.getX(), pos.getY(), unit.getMovementDistance());
                }
            }
        }
    }
示例#8
0
    protected float getRangePenalty(unitScript unit, float distance)
    {
        RangedWeapon weapon;
        float        rangedPenalty = 0.0f;

        try
        {
            weapon = (RangedWeapon)unit.getCurrentWeapon();
        } catch (InvalidCastException e)
        {
            return(distance > unit.getMovementDistance() + 2 ? 0 : 100);
        }

        if (weapon.minRange > distance)
        {
            rangedPenalty = weapon.minRange - distance;
        }
        else if (weapon.maxRange < distance)
        {
            rangedPenalty = distance - weapon.maxRange;
        }
        else
        {
            rangedPenalty = 0;
        }
        return(rangedPenalty);
    }
    void leftButtonPressed()
    {
        RaycastHit hit;
        var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, Mathf.Infinity, (1 << 8)))
        {
            DeselectCurrent();

            //set selected to hit
            selected = hit.collider.gameObject;

            //Select new unit
            if (selected)
            {
                unitScript unit = selected.GetComponent <unitScript>();

                if (unit != null)
                {
                    if (unit.getOwner() == 0)
                    {
                        selectUnit(unit);
                    }
                    else
                    {
                        DeselectCurrent();
                    }
                }
            }
        }
    }
 public void setCombatPanelVisibility(bool value, unitScript attacker = null, unitScript defender = null, float chanceToHit = 0.0f, float defenderChanceToHit = 0.0f)
 {
     if (value && attacker && defender)
     {
         loadCombatData(attacker, defender, chanceToHit, defenderChanceToHit);
     }
     transform.FindChild("CombatPanel").gameObject.SetActive(value);
 }
    protected override bool Attack(unitScript unit, unitScript clickedUnit)
    {
        bool value = base.Attack(unit, clickedUnit);

        if (value)
        {
            attackMode            = false;
            rangeRenderer.enabled = false;
            gui.GetComponent <GUIController>().hideRangedPanel();
            map.UnHilightMap();
        }
        return(value);
    }
示例#12
0
    void OnMouseDown()                                                                                                    //when the user clicks on this sector
    {
        gameMapScript theGameMapScript = this.gameMap.GetComponent <gameMapScript>();                                     //set a reference to the gameMapScript script of the gameMap
        GameObject    theSelectedUnit  = theGameMapScript.selectedUnit;                                                   //set a reference to the gameMap's selected unit to see if a unit was selected before this sector was clicked on

        theGameMapScript.selectedUnit = null;                                                                             //a sector has now been selected, so set the selectedUnit to null

        if (theSelectedUnit != null && theSelectedUnit.GetComponent <unitScript>().canMoveTo().Contains(this.gameObject)) //if a unit has been selected, and this sector has been clicked, move
        {                                                                                                                 //that unit to this sector, if it is within range
            unitScript theSelectedUnitScript = theSelectedUnit.GetComponent <unitScript>();                               //set a reference to the selected unit's unitScript script
            theSelectedUnitScript.moveUnit(this.gameObject);                                                              //move unit to this sector
        }
    }
示例#13
0
 protected virtual bool Attack(unitScript unit, unitScript clickedUnit)
 {
     //determine attack type
     if (unit.getCurrentWeapon().type == WeaponType.melee)
     {
         return(MeleeAttack(unit, clickedUnit));
     }
     if (unit.getCurrentWeapon().type == WeaponType.ranged)
     {
         return(RangedAttack(unit, clickedUnit));
     }
     return(false);
 }
示例#14
0
    bool swapTo(unitScript unit, WeaponType type)
    {
        for (int i = 0; i < unit.getWeaponCount(); i++)
        {
            if (unit.getWeapon(i).type == type)
            {
                unit.setCurrentWeapon(i);
                return(true);
            }
        }

        return(false);
    }
示例#15
0
    public bool isEnemyOnTile(string player)
    {
        if (unitsOnTerrain[0])
        {
            unitScript enemyScript = unitsOnTerrain[0].GetComponent <unitScript>();

            return(player != enemyScript.getOwner());
        }
        else
        {
            return(!unitsOnTerrain[0]);
        }
    }
    public override void spawnTeam()
    {
        Vector2[] spawns = map.getSpawnPoints();



        XmlDocument xml = new XmlDocument();

        xml.LoadXml(playerData.text);

        XmlNode data = xml.SelectSingleNode("data");

        playerUnitList = new unitScript[data.ChildNodes.Count];

        for (int i = 0; i < data.ChildNodes.Count; i++)
        {
            if (LevelData.party[i] != 1)
            {
                playerUnitList[i] = null;
                continue;
            }

            XmlNode    current        = data.ChildNodes[i];
            string     unitName       = current.SelectSingleNode("name").InnerText;
            string     unitClass      = current.SelectSingleNode("class").InnerText;
            int        health         = int.Parse(current.SelectSingleNode("health").InnerText);
            int        speed          = int.Parse(current.SelectSingleNode("speed").InnerText);
            int        skill          = int.Parse(current.SelectSingleNode("skill").InnerText);
            int        strength       = int.Parse(current.SelectSingleNode("strength").InnerText);
            int        smarts         = int.Parse(current.SelectSingleNode("smarts").InnerText);
            string     portraitString = current.SelectSingleNode("portait").InnerText;
            string     source         = current.SelectSingleNode("source").InnerText;
            GameObject newUnit        = (GameObject)Instantiate(Resources.Load(source), transform, true);
            unitScript unit           = newUnit.GetComponent <unitScript>();

            XmlNode       weaponNode  = current.SelectSingleNode("weapons");
            List <string> unitWeapons = new List <string>();
            foreach (XmlNode weapon in weaponNode.ChildNodes)
            {
                unitWeapons.Add(weapon.InnerText);
            }

            unit.setData(unitName, unitClass, health, speed, skill, strength, smarts, portraitString, unitWeapons);
            unit.gameObject.layer = 8;

            unit.setPosition(Mathf.FloorToInt(spawns[i].x), Mathf.FloorToInt(spawns[i].y));
            playerUnitList[i] = unit;
            unitsInGame.Add(unit);
        }
        gui.GetComponent <GUIController>().setPlayerTeam(playerUnitList);
    }
    public void loadCombatData(unitScript attacker, unitScript defender, float AttackerChanceToHit, float defenderChanceToHit)
    {
        Transform combatPanel = transform.Find("CombatPanel");
        Transform EnemyPanel  = combatPanel.Find("EnemyPanel");

        var targetText = EnemyPanel.Find("Target").GetComponent <UnityEngine.UI.Text>();

        targetText.text = defender.getName();

        var classText = EnemyPanel.Find("Class").GetComponent <UnityEngine.UI.Text>();

        classText.text = defender.getClass();

        var healthText = EnemyPanel.Find("Health").GetComponent <UnityEngine.UI.Text>();

        healthText.text = defender.getHealth().ToString() + " : " + defender.getMaxHealth().ToString();

        var strikeBack = EnemyPanel.Find("StrikeBack").GetComponent <Text>();

        strikeBack.text = (!defender.getStrikeback()).ToString();

        var strikebackChanceText = EnemyPanel.Find("ChanceText").GetComponent <Text>();
        var strikebackDamageText = EnemyPanel.Find("DamageText").GetComponent <Text>();

        var strikebackChance = EnemyPanel.Find("Chance").GetComponent <Text>();
        var strikebackDamage = EnemyPanel.Find("Damage").GetComponent <Text>();


        if (!defender.getStrikeback())
        {
            strikebackChance.enabled     = true;
            strikebackDamage.enabled     = true;
            strikebackChanceText.enabled = true;
            strikebackDamageText.enabled = true;

            strikebackChance.text = defenderChanceToHit.ToString();

            strikebackDamage.text = defender.getCurrentWeapon().damage.ToString();
        }
        else
        {
            strikebackChance.enabled     = false;
            strikebackDamage.enabled     = false;
            strikebackChanceText.enabled = false;
            strikebackDamageText.enabled = false;
        }
        int chance = (int)Mathf.Max(0, Mathf.Min(100, AttackerChanceToHit * 100));

        combatPanel.Find("ChanceToHit").GetComponent <UnityEngine.UI.Text>().text = (chance).ToString() + "%";
        combatPanel.Find("Damage").GetComponent <UnityEngine.UI.Text>().text      = unit.getCurrentWeapon().damage.ToString();
    }
示例#18
0
    protected bool RangedAttack(unitScript unit, unitScript clickedUnit, bool initialAttack = true)
    {
        // Check LoS
        if (!canSee(unit, clickedUnit))
        {
            return(false);
        }

        if (hitShield(unit, clickedUnit))
        {
            return(true);
        }

        //Resolve Attack

        float roll        = UnityEngine.Random.Range(0.0f, 1.0f);
        float chanceToHit = rangedChanceToHit(unit, clickedUnit);

        print(roll + " " + chanceToHit);
        if (roll < chanceToHit)
        {
            clickedUnit.takeDamage(unit.getCurrentWeapon().damage);
        }
        else
        {
            clickedUnit.displayMiss();
        }
        unit.activateAttack();
        if (initialAttack && clickedUnit.getStrikeback() == false)
        {
            bool result;
            if (clickedUnit.getCurrentWeapon().type == WeaponType.melee)
            {
                result = MeleeAttack(clickedUnit, unit, false);
            }
            else if (clickedUnit.getCurrentWeapon().type == WeaponType.ranged)
            {
                result = RangedAttack(clickedUnit, unit, false);
            }
            else
            {
                result = false;
            }
            if (result)
            {
                clickedUnit.useStrikeback();
            }
        }
        return(true);
    }
示例#19
0
    void fallBack(unitScript unit)
    {
        pathFinder.getMovementPaths(unit.GetComponent <GridItem>().getPos(), unit.getMovementDistance(), false);
        //run away from enemy
        //Calculate vector



        //if has shield switch to it and deploy
        if (swapTo(unit, WeaponType.shield))
        {
            activateShield(unit, unit.GetComponent <GridItem>());
        }
    }
示例#20
0
    protected bool isShielded(unitScript unit, unitScript clickedUnit)
    {
        Ray   ray      = new Ray(unit.transform.position + new Vector3(0, 1, 0), (clickedUnit.transform.position + new Vector3(0, 1, 0) - unit.transform.position + new Vector3(0, 1, 0)));
        float distance = Vector3.Distance(unit.transform.position, clickedUnit.transform.position);

        RaycastHit[] hits = Physics.RaycastAll(ray, distance);

        foreach (RaycastHit hit in hits)
        {
            if (hit.transform.gameObject.layer == 11)
            {
                return(true);
            }
        }
        return(false);
    }
示例#21
0
    protected bool activateShield(unitScript unit, GridItem position)
    {
        if (!(unit.getCurrentWeapon().type == WeaponType.shield))
        {
            return(false);
        }
        Shield currentShield = (Shield)unit.getCurrentWeapon();

        if (currentShield.isBroken(unit.GetInstanceID()))
        {
            return(false);
        }

        if (currentShield.getShield(unit.GetInstanceID()) != null)
        {
            Destroy(currentShield.getShield(unit.GetInstanceID()));
        }

        //Check position is within range
        if (currentShield == null || Vector2.Distance(unit.GetComponent <GridItem>().getPos(), position.getPos()) > currentShield.range)
        {
            return(false);
        }
        //Create the game object
        //TODO- Fix the roation and shape of shields to be frontal not surround
        Vector3 toPosition = position.getVectorPostion() - unit.GetComponent <GridItem>().getVectorPostion();
        float   rotation   = Vector3.Angle(new Vector3(0, 0, 1), Vector3.Cross(toPosition, new Vector3(0, 1, 0)));

        print(rotation);
        GameObject newShield = Instantiate <GameObject>(Resources.Load <GameObject>("Units/Shield"), position.getVectorPostion(), Quaternion.Euler(0, rotation, 0));

        currentShield.setShield(unit.GetInstanceID(), newShield);

        newShield.GetComponent <shieldScript>().setStats(controllerID, unit.getSmarts() * 3);
        //Check it's collisions with other shields
        currentShield.shieldBreakCheck();


        unit.activateAttack();

        print("ACTIVATE SHIELD");
        map.UnHilightMap();



        return(true);
    }
    void rightButtonPressed()
    {
        if (selected)
        {
            unitScript unit = selected.GetComponent <unitScript>();
            if (unit != null && unit.getOwner() == 0)
            {
                RaycastHit hit;
                var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out hit, Mathf.Infinity, (1 << 8)))
                {
                    unitSelectedRightClick(hit, unit);
                }
            }
        }
    }
    public void loadCharacter(unitScript u, bool ally = true)
    {
        if (ally)
        {
            unit = u;
        }
        Transform characterPanel = transform;
        Transform statPannel     = characterPanel.Find(ally?"StatPanel":"EnemyStatPanel");

        UnityEngine.UI.Text nameText = statPannel.Find("Name").GetComponent <UnityEngine.UI.Text>();
        nameText.text = u.getName();

        statPannel.FindChild("Image").GetComponent <Image>().sprite = u.getPortrait();

        var strengthText = statPannel.Find("Strength").GetComponent <UnityEngine.UI.Text>();

        strengthText.text = u.getStrength().ToString();

        var skillText = statPannel.Find("Skill").GetComponent <UnityEngine.UI.Text>();

        skillText.text = u.getSkill().ToString();

        var speedText = statPannel.Find("Speed").GetComponent <UnityEngine.UI.Text>();

        speedText.text = u.getSpeed().ToString();

        var smartsText = statPannel.Find("Smarts").GetComponent <UnityEngine.UI.Text>();

        smartsText.text = u.getSmarts().ToString();

        loadHealth(u.getHealth(), u.getMaxHealth(), statPannel);

        if (ally)
        {
            if (unit.doorsWithinRange.Count > 0)
            {
                transform.FindChild("CharacterPanel").FindChild("DoorButton").GetComponent <Button>().interactable = true;
            }
            else
            {
                transform.FindChild("CharacterPanel").FindChild("DoorButton").GetComponent <Button>().interactable = false;
            }
        }

        loadWeaponData(u, ally);
    }
示例#24
0
    protected bool canSee(unitScript unit, unitScript clickedUnit)
    {
        Ray   ray      = new Ray(unit.transform.position + new Vector3(0, 1, 0), (clickedUnit.transform.position + new Vector3(0, 1, 0) - unit.transform.position + new Vector3(0, 1, 0)));
        float distance = Vector3.Distance(unit.transform.position, clickedUnit.transform.position);

        RaycastHit[] hits = Physics.RaycastAll(ray, distance);

        foreach (RaycastHit hit in hits)
        {
            if (hit.transform.gameObject.layer == 9)
            {
                print("shooting through wall");
                print(hit.transform.gameObject.name);
                return(false);
            }
        }
        return(true);
    }
示例#25
0
    public void addUnit(int typeIndex, int x, int y)
    {
        EnemyType[] types   = map.getEnemyTypes();
        EnemyType   type    = types[typeIndex];
        GameObject  newUnit = (GameObject)Instantiate(Resources.Load(type.source), transform, true);
        unitScript  unit    = newUnit.GetComponent <unitScript>();

        unit.setData(type.unitName, type.unitClass, type.health, type.speed, type.skill, type.strength, type.smarts, "", new List <string>(type.weapons));
        unit.gameObject.layer = 8;
        unit.setPosition(x, y);
        unit.setOwner(1);
        AIUnitController ai = unit.gameObject.AddComponent <AIUnitController>();

        ai.healthThreshold = type.healthThreshold;
        List <unitScript> newList = new List <unitScript>(playerUnitList);

        newList.Add(unit);
        this.playerUnitList = newList.ToArray();
        unitsInGame.Add(unit);
    }
示例#26
0
    protected float rangedChanceToHit(unitScript unit, unitScript clickedUnit)
    {
        if (unit.getCurrentWeapon().type == WeaponType.melee)
        {
            return(0.0f);
        }
        //Calculate range penalty
        float distance = Vector2.Distance(unit.GetComponent <GridItem>().getPos(), clickedUnit.GetComponent <GridItem>().getPos());

        float rangedPenalty = getRangePenalty(unit, distance);

        //Calculate cover penalty
        float coverPenalty = getCoverPenalty(unit, clickedUnit, distance);

        //Get base shooting skill
        float shootingSkill = getBaseHitChance(unit);

        //Return formula
        return(shootingSkill - (rangedPenalty + coverPenalty) / 10);
    }
示例#27
0
    protected bool hitShield(unitScript unit, unitScript clickedUnit)
    {
        Ray   ray      = new Ray(unit.transform.position + new Vector3(0, 1, 0), (clickedUnit.transform.position + new Vector3(0, 1, 0) - unit.transform.position + new Vector3(0, 1, 0)));
        float distance = Vector3.Distance(unit.transform.position, clickedUnit.transform.position);

        RaycastHit[] hits = Physics.RaycastAll(ray, distance).OrderBy(h => h.distance).ToArray();

        foreach (RaycastHit hit in hits)
        {
            if (hit.transform.gameObject.layer == 11)
            {
                shieldScript shield = hit.transform.gameObject.GetComponent <shieldScript>();
                if (shield.owner != controllerID)
                {
                    shield.takeDamage(unit.getCurrentWeapon().damage);
                }
                return(true);
            }
        }
        return(false);
    }
    void unitSelectedRightClick(RaycastHit hit, unitScript unit)
    {
        clickableTile tile = hit.collider.gameObject.GetComponent <clickableTile>();

        if (tile)
        {
            GridItem tilePos = tile.GetComponent <GridItem>();
            GridItem pos     = selected.GetComponent <GridItem>();

            if (!unit.hasMoved())
            {
                //draw path only if not in attack mode
                Vector2[] path = pathFinder.drawPath(tilePos.getPos(), !attackMode);


                if (path != null)
                {
                    if (!attackMode && !unit.hasMoved())
                    {
                        map.UnHilightMap();
                        //map.toggleHighlight(false, Color.white, pos.getX(), pos.getY(), unit.getSpeed());
                        unit.setPath(path);
                        pathFinder.setPathfinding(false);
                    }
                }
            }
            if (attackMode && unit.getCurrentWeapon().type == WeaponType.shield)
            {
                activateShield(unit, tilePos);
            }
        }
        //If not tile may be unit
        unitScript clickedUnit = hit.collider.gameObject.GetComponent <unitScript>();

        // if is enemy unit
        if (attackMode && !unit.hasAttacked() && clickedUnit && clickedUnit.getOwner() != 0)
        {
            Attack(unit, clickedUnit);
        }
    }
示例#29
0
    protected bool MeleeAttack(unitScript unit, unitScript clickedUnit, bool initialAttack = true)
    {
        // Check attack can occur
        if (unit.getCurrentWeapon().type == WeaponType.ranged || unit == null || clickedUnit == null)
        {
            return(false);
        }

        float distance = Vector2.Distance(unit.GetComponent <GridItem>().getPos(), clickedUnit.GetComponent <GridItem>().getPos());

        if (!(unit.getCurrentWeapon().type == WeaponType.melee) || distance > ((MeleeWeapon)unit.getCurrentWeapon()).range)
        {
            return(false);
        }

        // Given it can roll the dice
        float roll = UnityEngine.Random.Range(0.0f, 1.0f);

        float chanceToHit = meleeChanceToHit(unit, clickedUnit);

        print(roll + " " + chanceToHit);
        if (roll < chanceToHit)
        {
            clickedUnit.takeDamage(unit.getStrength() + unit.getCurrentWeapon().damage);
        }
        else
        {
            clickedUnit.displayMiss();
        }
        unit.activateAttack();
        if (initialAttack && clickedUnit.getStrikeback() == false)
        {
            bool result = MeleeAttack(clickedUnit, unit, false);
            if (result)
            {
                clickedUnit.useStrikeback();
            }
        }
        return(true);
    }
示例#30
0
    void OnMouseDown()                                                                                                //when a building is clicked, it should open the unit buy menu and hide the game map
    {
        gameMapScript theGameMapScript = this.gameMap.GetComponent <gameMapScript>();                                 //set a reference to the gameMapScript script of the gameMap
        GameObject    theSelectedUnit  = theGameMapScript.selectedUnit;                                               //set a reference to the gameMap's selected unit to see if a unit was selected before this sector was clicked on

        theGameMapScript.selectedUnit = null;                                                                         //a sector has now been selected, so set the selectedUnit to null

        if (theSelectedUnit != null && theSelectedUnit.GetComponent <unitScript>().canMoveTo().Contains(this.sector)) //if a unit has been selected, and this building has been clicked, move
        {                                                                                                             //that unit to this sector, if it is within range
            unitScript theSelectedUnitScript = theSelectedUnit.GetComponent <unitScript>();                           //set a reference to the selected unit's unitScript script
            theSelectedUnitScript.moveUnit(this.sector);                                                              //move unit to this sector
        }
        else if (theSelectedUnit == null)
        {
            this.buyUnitCanvas.gameObject.SetActive(true);                                              //open the unit buying canvas
            this.gameMap.gameObject.SetActive(false);                                                   //close the game map
            buyUnitCanvas.GetComponent <unitCanvasScript>().warningMessage.gameObject.SetActive(false); //do not display the warningMessage
            //set the "spawnPoint" value in the buyUnitCanvas' "unitCanvasScript" script so that newly purchased units will spawn on the same sector
            //as the building that they clicked to open the buy unit menu
            this.buyUnitCanvas.GetComponent <unitCanvasScript>().setSpawnPoint(sector.gameObject);
        }
    }
示例#31
0
 // Use this for initialization
 void Start()
 {
     unit = GameObject.Find("Cube");
     //sword = GameObject.Find("sword");
     units = unit.GetComponent<unitScript>();
     _inventory = unit.GetComponent<Inventory>();
     intory = new Texture[9];
     itemPos = new Vector2[3];
     itemPos[0] = new Vector2(4, 70f);//y 45.5;
     itemPos[1] = new Vector2(54, 70f);
     itemPos[2] = new Vector2(102, 70f);// y 63.5;
     Window = new Rect(600, 100, 320, 340);
     bufftimeArmor = 10;
     bufftimeDamage = 30;
     Weapon = 0;
     menu = 0;
     ArmorLevel = 0;
     standardDamage = 10;
     canPick = false;
     Switcher = false;
     Damage = false;
     Armor = false;
     ray = true;
     SkillMenuBool = false;
 }
示例#32
0
 void Start()
 {
     pos = transform.position;
     Npos = new Vector3(transform.position.x, transform.position.y, transform.position.z);
     num = 0;
     HpBar.SetActive(false);
     player = GameObject.Find("Cube").transform;
     playerg = GameObject.Find("Cube");
     sword = GameObject.Find("sword");
     animSW = sword.GetComponent<Animator>();
     ToClose = GameObject.Find("combat").transform;
     spawner = GameObject.Find("spawner");
     snail = spawner.GetComponent<SnailSpawnScript>();
     unit = playerg.GetComponent<unitScript>();
     CS = playerg.GetComponent<GUIScript>();
     gameObject.name = "enemy";
     Health = fullHealth;
     timer = 1.5f;
     timer2 = 0f;
     CanAttack = false;
     Moving = false;
     Ro = true;
 }
示例#33
0
    void Start()
    {
        id = renderer.material.mainTexture.name;
        amount = 1;
        type = "inven";
        inventoryPic = renderer.material.mainTexture;
        unit = GameObject.Find("Cube");
        Gui = unit.GetComponent<GUIScript>();
        un = unit.GetComponent<unitScript>();
        Lo = GetComponent<LootScript>();
        _inventory = unit.GetComponent<Inventory>();//new Inventory(unit, Gui);

        switch (id)
        {
            case "HP potion":
                stackable = true;
                Consumeable = true;
                break;
            case "Armor potion":
                stackable = true;
                Consumeable = true;
                break;
            case "Strenght potion":
                stackable = true;
                Consumeable = true;
                break;
            case "Snail slime":
                stackable = true;
                Consumeable = false;
                break;
            case "Sword switcher":
                stackable = false;
                Consumeable = false;
                break;
            case "Mushroom":
                stackable = true;
                Consumeable = false;
                break;
        }
    }