Ejemplo n.º 1
0
 public Player(ArmyManager man, Color c)
 {
     ArmyList  = new List <Army>();
     Color     = c;
     Resources = new ResourceBag();
     manager   = man;
 }
Ejemplo n.º 2
0
 public void Add(ResourceBag other)
 {
     foreach (ResourceType resourceType in Enum.GetValues(typeof(ResourceType)))
     {
         this.SetAmountOf(resourceType, this.GetAmountOf(resourceType) + other.GetAmountOf(resourceType));
     }
 }
Ejemplo n.º 3
0
    // Start is called before the first frame update
    void Start()
    {
        hitDetect          = GetComponentInChildren <HitDetection>();
        attackAnimator     = GetComponentInChildren <Animator>();
        shootingProjectile = GetComponent <ShootingProjectiles>();
        stats         = GetComponent <PlayerStats>();
        body          = GetComponent <Rigidbody2D>();
        currentHealth = stats.getHealth();
        resources     = GetComponent <ResourceBag>();
        resources.initEmpty();

        abovePlayerUI = (Instantiate(Resources.Load("UI/Healthbar")) as GameObject);
        healthbar     = abovePlayerUI.GetComponentInChildren <Slider>();
        nameUI        = abovePlayerUI.GetComponentInChildren <TMPro.TextMeshProUGUI>();

        spawn           = new Vector2(transform.position.x, transform.position.y);
        timeOfLastClick = Time.time;

        if (isLocalPlayer)
        {
            hitDetect.isTheLocalPlayer = true;
            uiControl        = GameObject.FindObjectOfType <UI_Control>();
            uiControl.player = this;
            UI_Camera uiCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <UI_Camera>();
            mnmenu = GameObject.FindObjectOfType <MonumentalNetworkMenu>();
            uiCamera.followTarget = this.gameObject;
            currentHealth         = stats.getHealth();
            spriteRender          = this.GetComponent <SpriteRenderer>();
            spriteRender.sprite   = classSprites[stats.Class];
        }
    }
Ejemplo n.º 4
0
 // 0 for team 1; 1 for team 2 because indexing
 // Start is called before the first frame update
 void Start()
 {
     myCol     = this.GetComponent <Collider2D>();
     resPool   = GetComponent <ResourceBag>();
     baseStats = GetComponent <PlayerStats>();
     TeleportTile[] tels = GetComponentsInChildren <TeleportTile>();
     mnm          = GameObject.Find("NetworkManager").GetComponent <MonumentalNetworkManager>();
     gameSettings = GameObject.FindObjectOfType <GameSettings>();
     uiControl    = GameObject.FindObjectOfType <UI_Control>();
     lastPurchase = Time.time;
     for (int i = 0; i < tels.Length; i++)
     {
         tels[i].teamIndex = teamIndex;
     }
     if (isServer)
     {
         upgrade1level = 1;
         upgrade2level = 1;
         upgrade3level = 1;
         upgrade4level = 1;
         upgrade5level = 1;
         upgrade6level = 1;
     }
     monuments = GameObject.FindObjectOfType <Monuments>();
 }
Ejemplo n.º 5
0
    public Province(City city, Player owner)
    {
        PassiveResources = new ResourceBag();
        ActiveResources  = new ResourceBag();
        City             = city;
        Owner            = owner;

        // for now, default regen rates = 10 for food and 5 for weapons if there is a city, otherwise 0
        // it may be changed in the future (need to discuss design) s.t. cities generate resources and they permeate upwards or tweak interface
    }
Ejemplo n.º 6
0
    void Start()
    {
        List <AstronomicalBody> prefabs = getPrefabsToSpawn();
        List <AstronomicalBody> spawned = new List <AstronomicalBody>();

        int attemptedSpawnConfigurations = 0;

        while (spawned.Count < prefabs.Count && attemptedSpawnConfigurations < 1000)
        {
            List <Vector3> unitSphereDistribution = fibonacciSphere(prefabs.Count, true);

            for (int i = 0; i < prefabs.Count; i++)
            {
                Vector3 point;
                int     tryCount = 0;

                do
                {
                    point = transform.position + unitSphereDistribution[i] * RandomExtra.Range(DistanceFromSpawnRange);
                    tryCount++;
                } while (Physics.CheckSphere(point, prefabs[i].MinDistanceFromOtherColliders) && tryCount < SPAWN_TRIES_PER_PLANET);

                if (tryCount >= SPAWN_TRIES_PER_PLANET)
                {
                    foreach (AstronomicalBody spawn in spawned)
                    {
                        DestroyImmediate(spawn.gameObject);
                    }

                    spawned = new List <AstronomicalBody>();
                    attemptedSpawnConfigurations++;
                    break;
                }

                spawned.Add(Instantiate(prefabs[i], point, UnityEngine.Random.rotation));
            }
        }

        Debug.Log(attemptedSpawnConfigurations);

        if (attemptedSpawnConfigurations >= 1000)
        {
            throw new Exception("couldn't find a working configuration in a reasonable amount of time");
        }

        Goals = getGoals(prefabs);
    }
Ejemplo n.º 7
0
    ResourceBag getGoals(List <AstronomicalBody> bodies)
    {
        ResourceBag potentialGoals = new ResourceBag(0, 0, 0, 0);

        foreach (ResourceBag bag in bodies.Select(b => b.ResourceProfile))
        {
            potentialGoals += bag;
        }

        return(new ResourceBag
               (
                   0,
                   UnityEngine.Random.Range(potentialGoals.Hydrogen / 2, potentialGoals.Hydrogen) / 10 * 10,
                   UnityEngine.Random.Range(potentialGoals.Methane / 2, potentialGoals.Methane) / 10 * 10,
                   UnityEngine.Random.Range(potentialGoals.Silicon / 2, potentialGoals.Silicon) / 10 * 10
               ));
    }