Beispiel #1
0
 void OnGameBuildingPlaced(string buildingId, int playerNum, GameBuildingType type, Vector2 position)
 {
     if (PlayersManager.Instance.Me.Num == playerNum)
     {
         // notify other players when we place a building
         RPC.Instance.SendGameBuildingPlaced(buildingId, playerNum, type, position);
     }
 }
Beispiel #2
0
 private void OnGameBuildingPlaced(string buildingId, int playerNum, GameBuildingType type, Vector2 position)
 {
     if (Data.Num == playerNum)
     {
         var buildingCost = Constants.BuildingCosts[type];
         Data.Resources[buildingCost.Type1] -= buildingCost.Cost;
         if (buildingCost.Type2 != ResourceType.EXCEPTIION)
         {
             Data.Resources[buildingCost.Type2] -= buildingCost.Cost;
         }
         Signals.PublishPlayerUpdatedEvent(Data);
     }
 }
Beispiel #3
0
    private void OnGameBuildingSelected(GameBuildingType type)
    {
        // hide the mouse because the building becomes our mouse
        Input.SetMouseMode(Input.MouseMode.Hidden);

        var scene = ResourceLoader.Load <PackedScene>(type.GetScenePath());

        instancedScene = (GameBuilding)scene.Instance();
        instancedScene.NewlySpawned = true;
        instancedScene.PlayerNum    = PlayersManager.Instance.Me.Num;
        instancedScene.Type         = type;
        AddChild(instancedScene);
    }
Beispiel #4
0
    private void OnGameBuildingPlaced(string buildingId, int playerNum, GameBuildingType type, Vector2 position)
    {
        var          scene    = ResourceLoader.Load <PackedScene>(type.GetScenePath());
        GameBuilding building = (GameBuilding)scene.Instance();

        building.PlayerNum  = playerNum;
        building.Position   = position;
        building.BuildingId = buildingId;
        building.Active     = true;
        AddChild(building);

        PlayersManager.Instance.GetPlayer(playerNum).AddScore(ScoreType.BuildingBuilt);
    }
Beispiel #5
0
    public static String GetName(this GameBuildingType type)
    {
        switch (type)
        {
        case GameBuildingType.PowerPlant:
            return("Power Plant");

        case GameBuildingType.ScienceLab:
            return("Science Lab");

        default:
            return(type.ToString());
        }
    }
Beispiel #6
0
    /// <summary>
    /// Check if this player can afford a building
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public bool CanAffordBuilding(GameBuildingType type)
    {
        var buildingCost = Constants.BuildingCosts[type];

        // if we can't afford building type one, return false
        if (Resources[buildingCost.Type1] < buildingCost.Cost)
        {
            return(false);
        }

        // if we have a type2, check if we have enough resources
        if (buildingCost.Type2 != ResourceType.EXCEPTIION &&
            Resources[buildingCost.Type2] < buildingCost.Cost)
        {
            return(false);
        }

        // we have enough of both types, return true because we can afford it
        return(true);
    }
Beispiel #7
0
 public static void PublishGameBuildingSelectedEvent(GameBuildingType type)
 {
     GameBuildingSelectedEvent?.Invoke(type);
 }
Beispiel #8
0
 public static void PublishGameBuildingPlacedEvent(string buildingId, int playerNum, GameBuildingType type, Vector2 position)
 {
     GameBuildingPlacedEvent?.Invoke(buildingId, playerNum, type, position);
 }
Beispiel #9
0
    /// <summary>
    /// Return the path to a GameBuilding scene based on its type
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public static string GetScenePath(this GameBuildingType type)
    {
        var folder = type.IsDefenseBuilding() ? "DefenseBuildings" : "ResourceBuildings";

        return($"res://src/GameObjects/{folder}/{type.ToString()}.tscn");
    }
Beispiel #10
0
 public static bool IsResourceBuilding(this GameBuildingType type)
 {
     return(type == GameBuildingType.Mine || type == GameBuildingType.PowerPlant || type == GameBuildingType.ScienceLab);
 }
Beispiel #11
0
 public static bool IsDefenseBuilding(this GameBuildingType type)
 {
     return(type == GameBuildingType.Laser || type == GameBuildingType.Radar || type == GameBuildingType.Shield || type == GameBuildingType.Missile);
 }