Example #1
0
    public void onButtonPressed(int index)
    {
        // TODO: this is invalid for non ownable items, so must be changed later on
        if (player.GetPower() >= blueprint.items[index].cost && player.faction == vendor.GetFaction() &&
            player.unitsCommanding.Count < player.GetTotalCommandLimit())
        {
            GameObject creation = new GameObject();
            switch (blueprint.items[index].entityBlueprint.intendedType)
            {
            case EntityBlueprint.IntendedType.Turret:
                Turret tur = creation.AddComponent <Turret>();
                tur.blueprint = blueprint.items[index].entityBlueprint;
                tur.SetOwner(player);
                break;

            case EntityBlueprint.IntendedType.Tank:
                Tank tank = creation.AddComponent <Tank>();
                tank.blueprint   = blueprint.items[index].entityBlueprint;
                tank.enginePower = 250;
                tank.SetOwner(player);
                break;

            default:
                break;
            }
            creation.name = blueprint.items[index].entityBlueprint.name;
            player.sectorMngr.InsertPersistentObject(blueprint.items[index].entityBlueprint.name, creation);
            creation.transform.position = vendor.GetPosition();
            creation.GetComponent <Entity>().spawnPoint = vendor.GetPosition();
            if (blueprint.items[index].entityBlueprint.intendedType != EntityBlueprint.IntendedType.Tank)
            {
                player.SetTractorTarget(creation.GetComponent <Draggable>());
            }
            player.AddPower(-blueprint.items[index].cost);
            if (GetActive())
            {
                CloseUI();
            }
            ClearVendor();
        }
        else if (player as PlayerCore && player.GetUnitsCommanding().Count >= player.GetTotalCommandLimit())
        {
            player.alerter.showMessage("Unit limit reached!", "clip_alert");
        }
    }