[RPC] void SummonCreature(NetworkViewID viewID, int cretID, NetworkViewID vid2, bool isHero, int player)
    {
        Network.Destroy(vid2);
        NetworkView    nv = NetworkView.Find(viewID);
        CreatureScript cs = nv.GetComponent <CreatureScript>();

        print(cretID);
        cs.playerID = this.playerID;
        if (isHero)
        {
            TurnManager.instance.heroObjects[this.playerID] = cs;
            cs.playerID = this.playerID;
        }
        else
        {
            cs.attack      = CardDatabase.instance.cards[cretID].statA;
            cs.health      = cs.maxhealth = CardDatabase.instance.cards[cretID].statB;
            cs.cardTex     = CardDatabase.instance.cards[cretID].cardPicture;
            cs.name        = CardDatabase.instance.cards[cretID].name;
            cs.description = CardDatabase.instance.cards[cretID].descrip;
            cs.type        = CardDatabase.instance.cards[cretID].type;
            cs.flavor      = CardDatabase.instance.cards[cretID].flavor;
            cs.canAttack   = CardDatabase.instance.cards[cretID].boolA;
            cs.playerID    = this.playerID;
            cs.attacked    = CardDatabase.instance.cards[cretID].boolB;
            string desc = CardDatabase.instance.cards[cretID].descrip.Replace("\\n", "\n");
            cs.description = desc;
            string flav = CardDatabase.instance.cards[cretID].flavor.Replace("\\n", "\n");
            cs.flavor      = flav;
            cs.summonSound = CardDatabase.instance.cards[cretID].soundA;
            cs.attackSound = CardDatabase.instance.cards[cretID].soundB;
            cs.dieSound    = CardDatabase.instance.cards[cretID].soundC;
        }
    }
Esempio n. 2
0
    private void addMutationBlock(GameObject child)
    {
        CreatureScript childScript = child.GetComponent <CreatureScript>();
        GameObject     newBlock    = Instantiate(this.mutationBlocks[Random.Range(0, this.mutationBlocks.Length)],
                                                 child.transform);
        Vector3 blockPosition = getRandomBlockPosition(childScript);

        newBlock.transform.localPosition = blockPosition;
        childScript.UpdateBody();
    }
Esempio n. 3
0
    private Vector3 getRandomBlockPosition(CreatureScript creature)
    {
        List <Vector3> options = new List <Vector3>();

        foreach (GameObject block in creature.blocks)
        {
            // can't spawn a block from a mouth (to prevent mouths being inside a body)
            if (block.tag == "Mouth")
            {
                continue;
            }

            // assume all faces have no adjascent blocks
            List <Vector3> blockOptions = new List <Vector3>();
            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    for (int k = -1; k < 2; k++)
                    {
                        Vector3 newOffset   = new Vector3(i, j, k);
                        Vector3 newPosition = block.transform.localPosition + newOffset;
                        if (!options.Contains(newPosition) && newOffset.magnitude == 1)
                        {
                            blockOptions.Add(newPosition);
                        }
                    }
                }
            }

            // remove all options that contain a block (this also removes the block 'block')
            foreach (GameObject adj in creature.blocks)
            {
                if (blockOptions.Contains(adj.transform.localPosition))
                {
                    blockOptions.Remove(adj.transform.localPosition);
                }
            }

            // log block options into all options
            options.AddRange(blockOptions);
        }

        // return a random block
        if (options.Count != 0)
        {
            Vector3 randomPosition = options[Random.Range(0, options.Count)];
            return(randomPosition);
        }
        else
        {
            throw new NotImplementedException("Creature has no room for new block, shouldn't be possible.");
        }
    }
Esempio n. 4
0
    // Use this for initialization
    void Start()
    {
        //Get a reference to the creature and hold it so we only have to get it once
        creature       = (CreatureScript)GameObject.Find("Creature").GetComponent("CreatureScript");
        platformBridge = (NoticeReceiver)GameObject.Find("PlatformBridge").GetComponent("NoticeReceiver");

        // Assume the service is on when we start if there is no saved value.
        serviceToggle = (1 == PlayerPrefs.GetInt(SERVICE_TOGGLE, 1));

        // Don't display the privacy policy at start.
        displayPrivacyPolicy = false;
    }
    [RPC] void AttackOther(NetworkViewID nvid)
    {
        NetworkView    nv = NetworkView.Find(nvid);
        CreatureScript cs = nv.GetComponent <CreatureScript>();

        if (networkView.isMine)
        {
            networkView.RPC("PlaySound", RPCMode.All, 1);
            networkView.RPC("TakeDamage", RPCMode.All, cs.attack);
            nv.RPC("TakeDamage", RPCMode.All, attack);
        }
    }
Esempio n. 6
0
    private void UpdateChildBrain(CreatureScript childScript, CreatureScript parentScript)
    {
        for (int i = 0; i < parentScript.brain.weights.Length; i++)
        {
            for (int j = 0; j < parentScript.brain.weights[i].Length; j++)
            {
                childScript.brain.weights[i][j] = parentScript.brain.weights[i][j];
            }
        }

        for (int i = 0; i < parentScript.brain.biases.Length; i++)
        {
            childScript.brain.biases[i] = parentScript.brain.biases[i];
        }
    }
Esempio n. 7
0
    [RPC] void AttackOther(NetworkViewID nvid)
    {
        NetworkView    nv = NetworkView.Find(nvid);
        CreatureScript cs = nv.GetComponent <CreatureScript>();

        if (networkView.isMine)
        {
            networkView.RPC("PlaySound", RPCMode.All, 1);
            if (!CardDatabase.instance.cards[this.cardID].abilities.Contains(CardType.CardAbilities.Ranged))
            {
                networkView.RPC("TakeDamage", RPCMode.All, cs.attack);
            }
            nv.RPC("TakeDamage", RPCMode.All, attack);
        }
        if (CardDatabase.instance.cards[this.cardID].abilities.Contains(CardType.CardAbilities.Airborne))
        {
            attackedAirborne = true;
        }
    }
    public void SetMyCreature(CreatureScript creat)
    {
        myCreature = creat;
        myCreature.SetRandomPosition(indexLayer);
        //myCreature.gameObject.transform.parent = transform;
        myCreature.gameObject.transform.position = new Vector3(0f,-17f,-1.83f);
        myCreature.gameObject.transform.localScale = new Vector3(6f,6f,6f);

        myCreature.myMatBase.SetTexture("_Perlin3",myMat.GetTexture("_Perlin3"));
        myCreature.myMatBase.SetTexture("_Perlin4",myMat.GetTexture("_Perlin4"));

        myCreature.myMatBase.SetTextureOffset("_Perlin3",new Vector2(myMat.GetTextureOffset("_Perlin3").x+myMat.GetTextureScale("_Perlin3").x,myMat.GetTextureOffset("_Perlin3").y+myMat.GetTextureScale("_Perlin3").y-0.5f));
        myCreature.myMatBase.SetTextureOffset("_Perlin4",new Vector2(myMat.GetTextureOffset("_Perlin4").x+myMat.GetTextureScale("_Perlin4").x,myMat.GetTextureOffset("_Perlin4").y+myMat.GetTextureScale("_Perlin4").y-0.5f));
        myCreature.myMatBase.SetTextureScale("_Perlin3",new Vector2(-myMat.GetTextureScale("_Perlin3").x,myMat.GetTextureScale("_Perlin3").y));
        myCreature.myMatBase.SetTextureScale("_Perlin4",new Vector2(-myMat.GetTextureScale("_Perlin4").x,myMat.GetTextureScale("_Perlin4").y));

        myCreature.myMatBase.SetFloat("_SizeClouds",myMat.GetFloat("_SizeClouds"));
        myCreature.myMatBase.SetColor("_ColorOutline",myMat.GetColor("_ColorOutline"));
        myCreature.myMatBase.SetFloat("_GlobalDistoForce",myMat.GetFloat("_GlobalDistoForce"));
        //myCreature.myMatBase.SetFloat("_SizeClouds",myMat.GetFloat("_SizeClouds"));
    }
Esempio n. 9
0
    private void UpdateCreatures()
    {
        List <GameObject> creaturesToKill = new List <GameObject>();
        List <GameObject> futureParents   = new List <GameObject>();

        foreach (GameObject creature in this.population)
        {
            ApplyFlowField(creature);
            CreatureScript creatureScript = creature.GetComponent <CreatureScript>();

            // ignore dead creatures, and kill them later
            if (creatureScript.dead)
            {
                creaturesToKill.Add(creature);
                continue;
            }

            // remember all creatures that want to have a child
            if (creatureScript.reproduce)
            {
                futureParents.Add(creature);
            }

            WrapObject(creature);
        }

        foreach (GameObject creature in futureParents)
        {
            if (this.population.Count < maxCreatures)
            {
                SpawnChild(creature);
            }
        }

        for (int i = 0; i < creaturesToKill.Count; i++)
        {
            KillCreature(creaturesToKill[0]);
        }
    }
Esempio n. 10
0
    private void SpawnChild(GameObject parent)
    {
        // parent actions
        CreatureScript parentScript = parent.GetComponent <CreatureScript>();

        parentScript.reproduce = false;

        // child actions
        GameObject     newChild    = Instantiate(parent, creatures);
        CreatureScript childScript = newChild.GetComponent <CreatureScript>();
        Vector3        offset      = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized;

        newChild.transform.SetPositionAndRotation(parent.transform.position + offset,
                                                  parent.transform.rotation);
        MutateCreature(newChild);
        AddToPopulation(newChild);

        // copy the weights and biases of the parent into the child
        // if any new weights appeared through mutation, they won't be affected
        // since all children of the transfroms will be the same (in the same order)
        // and the new blocks will appear last.
        UpdateChildBrain(childScript, parentScript);
    }
Esempio n. 11
0
    public void SaveCreatures()
    {
        //Debug.Log("SAVING CREATURES");

        string filePath = Application.persistentDataPath + fileName;

        //string filePath = fileName;

        //Debug.Log(filePath);

        if (File.Exists(filePath))
        {
            JsonCreatures jsonCreatures = new JsonCreatures()
            {
                names                     = new string[creaturesInWorld.Count],
                types                     = new string[creaturesInWorld.Count],
                worldIds                  = new int[creaturesInWorld.Count],
                happiness                 = new float[creaturesInWorld.Count],
                sizes                     = new float[creaturesInWorld.Count],
                stars                     = new int[creaturesInWorld.Count],
                intelligenceRank          = new string[creaturesInWorld.Count],
                intelligenceLevel         = new int[creaturesInWorld.Count],
                intelligenceUpgradePoints = new int[creaturesInWorld.Count],
                intelligenceScore         = new int[creaturesInWorld.Count],

                agilityRank          = new string[creaturesInWorld.Count],
                agilityLevel         = new int[creaturesInWorld.Count],
                agilityUpgradePoints = new int[creaturesInWorld.Count],
                agilityScore         = new int[creaturesInWorld.Count],

                strengthRank          = new string[creaturesInWorld.Count],
                strengthLevel         = new int[creaturesInWorld.Count],
                strengthUpgradePoints = new int[creaturesInWorld.Count],
                strengthScore         = new int[creaturesInWorld.Count],

                styleRank          = new string[creaturesInWorld.Count],
                styleLevel         = new int[creaturesInWorld.Count],
                styleUpgradePoints = new int[creaturesInWorld.Count],
                styleScore         = new int[creaturesInWorld.Count],

                staminaRank          = new string[creaturesInWorld.Count],
                staminaLevel         = new int[creaturesInWorld.Count],
                staminaUpgradePoints = new int[creaturesInWorld.Count],
                staminaScore         = new int[creaturesInWorld.Count],
            };
            int i = 0;
            foreach (var creature in creaturesInWorld)
            {
                CreatureScript CS = creature.GetComponent <CreatureScript>();

                jsonCreatures.names[i]     = CS.name;
                jsonCreatures.happiness[i] = CS.happiness;
                jsonCreatures.sizes[i]     = CS.size;
                jsonCreatures.types[i]     = CS.type;
                jsonCreatures.worldIds[i]  = creature.transform.parent.GetComponent <IslandScript>().islandID;
                jsonCreatures.stars[i]     = CS.Stars;

                jsonCreatures.intelligenceRank[i]          = CS.Intelligence.rank.name;
                jsonCreatures.intelligenceLevel[i]         = CS.Intelligence.level;
                jsonCreatures.intelligenceUpgradePoints[i] = CS.Intelligence.upgradePoints;
                jsonCreatures.intelligenceScore[i]         = CS.Intelligence.amt;

                jsonCreatures.agilityRank[i]          = CS.Agility.rank.name;
                jsonCreatures.agilityLevel[i]         = CS.Agility.level;
                jsonCreatures.agilityUpgradePoints[i] = CS.Agility.upgradePoints;
                jsonCreatures.agilityScore[i]         = CS.Agility.amt;

                jsonCreatures.strengthRank[i]          = CS.Strength.rank.name;
                jsonCreatures.strengthLevel[i]         = CS.Strength.level;
                jsonCreatures.strengthUpgradePoints[i] = CS.Strength.upgradePoints;
                jsonCreatures.strengthScore[i]         = CS.Strength.amt;

                jsonCreatures.styleRank[i]          = CS.Style.rank.name;
                jsonCreatures.styleLevel[i]         = CS.Style.level;
                jsonCreatures.styleUpgradePoints[i] = CS.Style.upgradePoints;
                jsonCreatures.styleScore[i]         = CS.Style.amt;

                jsonCreatures.staminaRank[i]          = CS.Stamina.rank.name;
                jsonCreatures.staminaLevel[i]         = CS.Stamina.level;
                jsonCreatures.staminaUpgradePoints[i] = CS.Stamina.upgradePoints;
                jsonCreatures.staminaScore[i]         = CS.Stamina.amt;
                i++;
            }

            string dataAsJson = JsonUtility.ToJson(jsonCreatures);

            File.WriteAllText(filePath, dataAsJson);

            //Debug.Log("Saved creatures");
        }
        else
        {
            File.Create(filePath).Dispose();
            SaveCreatures();
        }
    }
Esempio n. 12
0
 IEnumerator GoAndCatchCreature(CreatureScript creaturee)
 {
     yield return new WaitForSeconds(2f);
     network.SendCreatureCaught(creaturee.GetComponent<Creature>().Seed);
 }
Esempio n. 13
0
    void FixedUpdate()
    {
        if (TurnManager.instance.beginTurns[this.playerID])
        {
            foreach (CreatureScript cret in crets)
            {
                if (cret)
                {
                    cret.attacked         = false;
                    cret.attackedAirborne = false;
                }
            }
            TurnManager.instance.beginTurns[this.playerID] = false;
        }
        transform.position = pos[watchedPlayer].position;
        transform.rotation = pos[watchedPlayer].rotation;
        if (Network.isClient || Network.isServer)
        {
            if (!spawnedDeck)
            {
                playerID = Random.Range(0, maxPlayers);
                while (TurnManager.instance.playerDecks[playerID])
                {
                    playerID = Random.Range(0, maxPlayers);
                }
                GameObject  go   = (GameObject)Network.Instantiate(deckPrefab, deckPos[playerID].position, deckPos[playerID].rotation, 16);
                NetworkView deck = go.GetComponent <NetworkView>();
                CardDatabase.instance.GetComponent <NetworkView>().RPC("SpawnDeck", RPCMode.AllBuffered, deck.viewID, playerID, deckList);
                GameObject go2 = (GameObject)Network.Instantiate(heroPrefab, heroPos[playerID].position, heroPos[playerID].rotation, 8);
                CardDatabase.instance.GetComponent <NetworkView>().RPC("SpawnHero", RPCMode.AllBuffered, go2.GetComponent <NetworkView>().viewID, playerID);
                spawnedDeck   = true;
                watchedPlayer = playerID;
            }
            if (TurnManager.currentTurn == this.playerID)
            {
                float mposx = Input.mousePosition.x;
                float mposy = Input.mousePosition.y;
                if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
                {
                    if (Input.touchCount > 0)
                    {
                        Touch t = Input.GetTouch(0);
                        mposx = t.position.x;
                        mposy = t.position.y;
                    }
                }
                Ray        r = this.GetComponent <Camera>().ViewportPointToRay(new Vector3(mposx / Screen.width, mposy / Screen.height));
                RaycastHit rh;
                if (Physics.Raycast(r, out rh) && (Input.GetButton("Fire1") || Input.touchCount == 1))
                {
                    //print("THING!");
                    if (rh.collider.tag == "Card")
                    {
                        Card c = rh.collider.GetComponent <Card>();
                        if ((TurnManager.instance.rawMana[playerID] >= c.neutralCost || c.rb.isKinematic) && drawnCardThisTurn == false)
                        {
                            //if(c.rb.isKinematic)
                            //drawnCardThisTurn=true;
                            c.rb.isKinematic = false;
                            //print("THING TWO!");
                            Ray        r2 = this.GetComponent <Camera>().ScreenPointToRay(Input.mousePosition);
                            RaycastHit rh2;
                            Physics.Raycast(r2, out rh2);
                            Vector3 vec = rh2.point;
                            vec.y = 2f;
                            rh.transform.position = vec;
                            rh.rigidbody.velocity = Vector3.zero;
                            Quaternion q = Quaternion.identity;
                            q.eulerAngles         = angles[playerID];
                            rh.transform.rotation = q;
                        }
                    }
                    if (rh.collider.tag == "Creature")
                    {
                        CreatureScript cs = rh.collider.GetComponent <CreatureScript>();
                        if (cs.playerID == this.playerID)
                        {
                            if (!crets.Contains(cs))
                            {
                                crets.Add(cs);
                            }
                            selectedCreature = cs;
                        }
                        else
                        {
                            if (selectedCreature && selectedCreature.attacked == false)
                            {
                                bool canAttack = true;
                                if (CardDatabase.instance.cards[cs.cardID].abilities.Contains(CardType.CardAbilities.Airborne))
                                {
                                    if (cs.attackedAirborne == false)
                                    {
                                        canAttack = false;
                                    }
                                }
                                if (canAttack)
                                {
                                    selectedCreature.attacked = true;
                                    selectedCreature.networkView.RPC("AttackOther", RPCMode.All, cs.networkView.viewID);
                                }
                            }
                        }
                    }
                }

                /*if(Physics.Raycast(r, out rh) && Input.GetButtonUp("Fire2"))
                 * {
                 *      Collider[] cols = Physics.OverlapSphere(rh.point, 2.5f);
                 *      foreach(Collider c in cols)
                 *      {
                 *              if(c.attachedRigidbody)
                 *              {
                 *                      c.attachedRigidbody.AddForce(Vector3.up*500 + (new Vector3(Random.Range(-25, 25), Random.Range(-25, 25), Random.Range(-25, 25))));
                 *                      c.attachedRigidbody.AddTorque(Random.Range(-5, 5), Random.Range(-5, 5), Random.Range(-5, 5));
                 *              }
                 *      }
                 * }*/
            }
        }
    }
Esempio n. 14
0
 // Use this for initialization
 void Start()
 {
     //reference to CreatureScript once, and hold it so we only have to get it once
     creature = (CreatureScript)GameObject.Find("Creature").GetComponent("CreatureScript");
 }
Esempio n. 15
0
    // Update is called once per frame
    void Update()
    {
        //Handles size of the bar.
        timeLeft       = timeLeft - Time.deltaTime;
        currentSizeBar = blinkResize.transform.localScale.y;
        blinkResize.transform.localScale -= new Vector3(0, Time.deltaTime * 100, 0);

        //So that bar doesn't go below 0.
        if (blinkResize.transform.localScale.y <= 0.0f)
        {
            currentCycles++;
            CreatureScript c = creature.GetComponent <CreatureScript>();
            blinkResize.transform.localScale = new Vector3(1, 640, 1);
            reachZero = true;
            c.increaseThreatEmptyBar();
            //Debug.Log ("why");
        }

        //So that bar doesn't go above 640.
        if (blinkResize.transform.localScale.y > 640.0f)
        {
            blinkResize.transform.localScale = new Vector3(1, 640, 1);
        }

        //Adds to bar if player hits the right key
        if (Input.GetKeyDown(generatedCode))
        {
            blinkResize.transform.localScale += new Vector3(0, 100, 0);
            //Debug.Log("BINGO");
        }

        //Debug.Log (timeLeft);
        if (timeLeft < 0)
        {
            timeLeft = 5f;
            //Change key

            doGeneration();
            if (GlobalTimer.GetComponent <CountdownTimer>().ReturnGlobalTime() < 1f)
            {
                YouWin();
            }
            //Increase cycle count
            currentCycles++;

            if (!reachZero)
            {
                if (currentSizeBar < 320)
                {
                    CreatureScript c = creature.GetComponent <CreatureScript>();
                    c.NotDoingGood();
                    c.increaseThreat();
                    doingGoodCounter = 0;
                    if (GlobalTimer.GetComponent <CountdownTimer>().ReturnGlobalTime() <= 10f && randomKill <= 25)
                    {
                        GameOver();
                    }
                    generateRandomKill();
                }
                else
                {
                    CreatureScript d = creature.GetComponent <CreatureScript>();
                    doingGoodCounter++;
                    if (doingGoodCounter >= 3)
                    {
                        d.ReallyDoingGood();
                        doingGoodCounter = 3;
                    }
                    d.decreaseThreat();

                    reachZero = false;
                }
            }
            else
            {
                CreatureScript f = creature.GetComponent <CreatureScript>();
                f.NotDoingGood();
                f.increaseThreat();
                doingGoodCounter = 0;
                reachZero        = false;
                if (GlobalTimer.GetComponent <CountdownTimer>().ReturnGlobalTime() <= 10f && randomKill <= 25)
                {
                    GameOver();
                }
                generateRandomKill();
            }
        }
    }