Inheritance: AIController
Ejemplo n.º 1
0
    private void OnDragStart(GameObject obj)
    {
        CritterController critter        = obj.GetComponent <CritterController>();
        ItemDescriptor    itemDescriptor = obj.GetComponent <ItemDescriptor>();

        if (critter != null)
        {
            CreatureDescriptor dna = critter.GetDNA();
            StringBuilder      descStringBuilder = new StringBuilder();
            descStringBuilder.AppendLine(string.Format("Shape: {0}", CritterConstants.GetCreatureShapeDisplayString(dna.Shape)));
            descStringBuilder.AppendLine(string.Format("Color: {0}", CritterConstants.GetCreatureColorDisplayString(dna.Color)));
            descStringBuilder.AppendLine(string.Format("Size: {0}", CritterConstants.GetCreatureSizeDisplayString(dna.Size)));

            var attachmentCountMap = dna.GetAttachmentTypeCounts();
            foreach (var countPair in attachmentCountMap)
            {
                if (countPair.Value > 0)
                {
                    descStringBuilder.AppendLine(string.Format("{0}: {1}", countPair.Key.AttachmentType, countPair.Value));
                }
            }

            _itemDescText.SetText(descStringBuilder);
        }
        else if (itemDescriptor != null)
        {
            _itemDescText.SetText(itemDescriptor.Description);
        }
    }
Ejemplo n.º 2
0
    private void OnTriggerEnter(Collider other)
    {
        CritterController Critter = other.GetComponentInParent <CritterController>();

        if (Critter != null)
        {
            CustomerOrderManager.Instance.OnCreatureDeposited(Critter);
        }
    }
Ejemplo n.º 3
0
    private void MateWith(CritterController critter, bool isLeader)
    {
        _currentMate = critter;
        _isMoving    = false;

        GameObject mateFx = Instantiate(_mateEffectPrefab, transform);

        mateFx.transform.localPosition = Vector3.zero;

        if (isLeader)
        {
            _nearestMate.MateWith(this, isLeader: false);
            StartCoroutine(MateAsync());
        }
    }
Ejemplo n.º 4
0
    public static CreatureDescriptor CreateCreatureDescriptorFromParents(CritterController parent0, CritterController parent1)
    {
        CreatureDescriptor parentDNA0 = parent0.GetDNA();
        CreatureDescriptor parentDNA1 = parent1.GetDNA();
        CreatureDescriptor childDNA   = new CreatureDescriptor();

        // Randomly pick a color from one of the parents
        childDNA.Color = Random.Range(0, 1) == 0 ? parentDNA0.Color : parentDNA1.Color;

        // Randomly pick a shape from one of the parents
        childDNA.Shape = Random.Range(0, 1) == 0 ? parentDNA0.Shape : parentDNA1.Shape;

        // Always start small
        childDNA.Size = CritterConstants.CreatureSize.Small;

        // Combine the attachment from both parents into one big list
        List <GameObject> combinedParentAttachments = new List <GameObject>();

        combinedParentAttachments.AddRange(parentDNA0.Attachments);
        combinedParentAttachments.AddRange(parentDNA1.Attachments);

        List <CreatureAttachmentDescriptor> combinedParentAttachmentTypes = new List <CreatureAttachmentDescriptor>();

        combinedParentAttachmentTypes.AddRange(parentDNA0.AttachmentTypes);
        combinedParentAttachmentTypes.AddRange(parentDNA1.AttachmentTypes);

        // Create a shuffled index into the combined attachent list
        int[] shuffledParentAttachmentIndices = ArrayUtilities.MakeShuffledIntSequence(0, combinedParentAttachments.Count - 1);

        // Decide how many attachments the child will have
        //  1 -> SpawnAttachmentCount
        // but no more than parents had available to draw from
        int childAttachmentCount = System.Math.Min(System.Math.Max(CritterSpawner.Instance.SpawnAttachmentCount.RandomValue, 1), combinedParentAttachments.Count);

        // Fill in the child attachment list using the shuffled indices
        childDNA.Attachments     = new GameObject[childAttachmentCount];
        childDNA.AttachmentTypes = new CreatureAttachmentDescriptor[childAttachmentCount];
        for (int childAttachmentIndex = 0; childAttachmentIndex < childAttachmentCount; ++childAttachmentIndex)
        {
            int randomAttachmentIndex = shuffledParentAttachmentIndices[childAttachmentIndex];

            childDNA.Attachments[childAttachmentIndex]     = combinedParentAttachments[randomAttachmentIndex];
            childDNA.AttachmentTypes[childAttachmentIndex] = combinedParentAttachmentTypes[randomAttachmentIndex];
        }
        //childDNA.SortAttachments();

        return(childDNA);
    }
Ejemplo n.º 5
0
    public GameObject CreateDuplicate()
    {
        CritterController critter = GetComponent <CritterController>();
        GameObject        dupe;

        if (critter != null)
        {
            dupe = CritterSpawner.Instance.SpawnCritter(critter.GetDNA(), null);
        }
        else
        {
            dupe = Instantiate(_duplicatePrefab.Prefab);
            dupe.transform.SetParent(transform.parent);
        }

        Duplicated?.Invoke(dupe);
        return(dupe);
    }
Ejemplo n.º 6
0
    void OnCollisionEnter(Collision col)
    {
        if (rb.velocity.magnitude >= CrumbEmitForceThreshold)
        {
            CrumbsFX.Play();
        }

        CritterController hitCritter = col.transform.GetComponentInParent <CritterController>();

        //if(!hitCritter) Debug.LogWarning("No critter controller found on object: " + col.transform.parent.parent.name);

        if (!cding && hitCritter)
        {
            //Debug.LogWarning("Critter fed!");
            SetSandwichLevel(sandwichLvl + 1);
            cding = true;
        }
    }
Ejemplo n.º 7
0
    public GameObject SpawnCritter(CreatureDescriptor SpawnDescriptor, Transform SpawnTransformOverride)
    {
        GameObject CritterPrefab = GetCritterPrefab(SpawnDescriptor.Shape);
        GameObject NewCritter    = null;

        if (CritterPrefab != null)
        {
            Transform InitialTransform = SpawnTransformOverride != null ? SpawnTransformOverride : SpawnLocationTransform;

            NewCritter = Instantiate(CritterPrefab, InitialTransform.position, InitialTransform.rotation);

            CritterController ChildController = NewCritter.GetComponentInChildren <CritterController>();
            if (ChildController != null)
            {
                // Record the spawn descriptor (its "DNA") on the critter
                ChildController.SetDNA(SpawnDescriptor);
            }
        }

        return(NewCritter);
    }
Ejemplo n.º 8
0
    public void OnCreatureDeposited(CritterController critter)
    {
        bool bOrderSatisfied = false;

        if (_selectedOrderPanel != null)
        {
            // Get the order we are supposed to be fulfilling
            CustomerOrder order = _selectedOrderPanel.GetCustomerOrder();

            // Get the game object that owns the panel
            GameObject panelGameObject = _selectedOrderPanel.gameObject;

            // Remove the panel's GameObject from panel list
            _customerOrderPanelList.Remove(panelGameObject);

            // Deselect this panel
            // - closes the out hatch
            // - invalidates _selectedOrderPanel
            SetSelectedPanel(null);

            // Apply the creature too the order
            bOrderSatisfied = order.TrySatisfyDesireWithCreatureDescriptor(critter.GetDNA());

            // Add the order to the completed order list
            _completedOrdersList.Add(order);

            // Destroy the panel
            StartCoroutine(DehydrateOrderPanelAsync(panelGameObject));
        }

        // Play the appropriate effect
        if (_outHatchController != null)
        {
            _outHatchController.OnCrittedScored(bOrderSatisfied);
        }

        // Destroy the creature deposited in the hatch
        Destroy(critter.gameObject);
    }
Ejemplo n.º 9
0
    public void OnEnterStage(GameStage newGameStage)
    {
        switch (newGameStage)
        {
        case GameStage.MainMenu:
        {
            _mainMenu = (GameObject)Instantiate(MainMenuPrefab, Vector3.zero, Quaternion.identity);
            AudioManager.Instance.FadeInSound(gameObject, MusicMenuLoop, 3.0f);
        }
        break;

        case GameStage.PreGame:
        {
            _playerController = (GameObject)Instantiate(PlayerControllerPrefab, Vector3.zero, Quaternion.identity);
            AudioManager.Instance.FadeInSound(gameObject, MusicGameLoop, 3.0f);
            CustomerOrderManager.Instance.OnRoundStarted();

            if (_gameClockController != null)
            {
                _gameClockController.StartClock();
            }
        }
        break;

        case GameStage.Morning:
        {
        }
        break;

        case GameStage.Lunchtime:
        {
            if (SandwichPrefab != null)
            {
                _sandwich = (GameObject)Instantiate(SandwichPrefab, Camera.main.gameObject.transform.position + Vector3.forward * 0.75f, Quaternion.Euler(90.0f, 0.0f, 0.0f));
                _sandwich.GetComponent <Rigidbody>().useGravity  = false;
                _sandwich.GetComponent <Rigidbody>().isKinematic = true;
                _sandwich.GetComponent <Sandwich>().SetIsSandwichClickable();
            }
        }
        break;

        case GameStage.Afternoon:
        {
            _playerController = (GameObject)Instantiate(PlayerControllerPrefab, Vector3.zero, Quaternion.identity);
        }
        break;

        case GameStage.PostGame:
        {
            CritterController.DestroyAllCreatures();

            if (_gameClockController != null)
            {
                _gameClockController.StopClock();
            }

            CustomerOrderManager.Instance.OnRoundCompleted();
            AudioManager.Instance.FadeOutSound(gameObject, MusicGameLoop, 3.0f);
            //TODO: Spawn post game UI

            _endMenu = (GameObject)Instantiate(EndMenuPrefab, new Vector3(Camera.main.gameObject.transform.position.x, 2.65f, -3.24f), Quaternion.identity);
        }
        break;
        }
    }
Ejemplo n.º 10
0
 private void StopMating()
 {
     _currentMate          = null;
     _vigorLevel           = 0;
     _changeDirectionTimer = 0;
 }
Ejemplo n.º 11
0
    private void Update()
    {
        // Age over time
        _age = Mathf.Clamp01(_age + Time.deltaTime * kAgeRate);
        CritterConstants.CreatureSize ageNewSize = CritterConstants.GetCreatureSizeAtAge(_age);
        if (ageNewSize != _size)
        {
            SetSize(ageNewSize, animate: true);
        }

        // Gain vigor, if we're old enough
        if ((int)_size >= (int)kMinVigorSize)
        {
            _vigorLevel          = Mathf.Clamp01(_vigorLevel + Time.deltaTime * kVigorGainRate);
            _vigorUI.FillPercent = _vigorLevel;
        }

        // Change direction sometimes
        _changeDirectionTimer -= Time.deltaTime;
        if (_changeDirectionTimer < 0)
        {
            _changeDirectionTimer = _changeDirTimeRange.RandomValue;
            _desiredDirection     = Random.onUnitSphere.WithY(0).normalized;
            _isMoving             = Random.value > _moveChance;

            if (_animator != null)
            {
                _animator.SetBool(kAnimParamIsWalking, _isMoving);
            }
        }

        // Slowly change move direction towards current desired direction / rotate to face move direction
        _moveDirection = Mathfx.Damp(_moveDirection, _desiredDirection, 0.5f, Time.deltaTime * _turnSpeed).WithY(0);

        if (_moveDirection.magnitude > 0.1f)
        {
            Quaternion desiredRot = Quaternion.LookRotation(_moveDirection, Vector3.up);
            _rigidBody.rotation = Mathfx.Damp(_rigidBody.rotation, desiredRot, 0.5f, Time.deltaTime * _turnSpeed);
        }

        // Occaisonally raycast for obstacles
        _obstacleRaycastTimer -= Time.deltaTime;
        if (_obstacleRaycastTimer < 0)
        {
            _obstacleRaycastTimer = 2;

            RaycastHit hitInfo;
            if (Physics.Raycast(transform.position, _desiredDirection, out hitInfo, _obstacleAvoidDistance, _obstacleMask))
            {
                _desiredDirection     = Quaternion.Euler(0, 90, 0) * _desiredDirection;
                _changeDirectionTimer = _changeDirTimeRange.MaxValue;
                Debug.DrawLine(transform.position, hitInfo.point, Color.red, 1.0f);
            }
            else
            {
                Debug.DrawRay(transform.position, _desiredDirection * _obstacleAvoidDistance, Color.white, 0.5f);
            }
        }

        // If we have full vigor, look for the closest mate and go get em
        if (IsReadyForLove)
        {
            if (_mateSearchIndex >= _instances.Count)
            {
                _mateSearchIndex = 0;
            }

            // Find nearest available mate lazily over time
            if (_mateSearchIndex < _instances.Count)
            {
                CritterController potentialMate = _instances[_mateSearchIndex];
                if (potentialMate != this && potentialMate.IsReadyForLove)
                {
                    float distToMate        = Vector3.Distance(transform.position, potentialMate.transform.position);
                    float distToNearestMate = _nearestMate != null?Vector3.Distance(transform.position, _nearestMate.transform.position) : Mathf.Infinity;

                    if (distToMate < distToNearestMate)
                    {
                        _nearestMate = potentialMate;
                    }
                }

                ++_mateSearchIndex;
            }

            // Move towards current desired mate
            if (_nearestMate != null)
            {
                Vector3 toMateVec = _nearestMate.transform.position - transform.position;
                _changeDirectionTimer = 1;
                _isMoving             = true;
                _desiredDirection     = toMateVec.normalized;

                // If someone gets to our potential mate first we have to try for someone else
                if (!_nearestMate.IsReadyForLove)
                {
                    _nearestMate = null;
                    return;
                }

                // If we get close enough, begin the process
                float distToMate = toMateVec.magnitude;
                if (distToMate < kMinMateDistance)
                {
                    MateWith(_nearestMate, isLeader: true);
                }
            }
        }

        Debug.DrawRay(transform.position, _desiredDirection, Color.blue);
    }