public override bool OnRebuildObservers(HashSet <NetworkConnection> observers, bool initial)
    {
        if (OctreeManager.Get(OctreeType.Player) == null)
        {
            Debug.Log("Could not find an Octree for the Player type");
            return(false);
        }

        CachedObjectList.Clear();
        RelevantTo.Clear();
        OctreeManager.Get(OctreeType.Player).GetObjectsInRange(transform.position, CachedObjectList, Range);

        for (var i = 0; i < CachedObjectList.Count; i++)
        {
            var netID = CachedObjectList[i].GetComponent <NetworkIdentity>();
            if (netID == null)
            {
                continue;
            }

            RelevantTo.Add(netID.connectionToClient);
            observers.Add(netID.connectionToClient);
        }

        return(true);
    }
예제 #2
0
    public Nodule SpawnNodule(Vector3 pos, Quaternion rot, NoduleType type)
    {
        var nod = m_Nodules.SpawnNodule(pos, rot, type);

        OctreeManager.Get(OctreeType.Nodule).Add(nod.transform);
        return(nod);
    }
예제 #3
0
 public void RemoveNodule(Nodule con)
 {
     if (m_Nodules.Count != 0 && con != null)
     {
         m_Nodules.DisableNodule(con);
         OctreeManager.Get(OctreeType.Nodule).Remove(con.transform);
     }
 }
    public override void OnStartServer()
    {
        NoduleSensor = new OctreeSensor <Nodule>(transform, SensingRadius, OctreeManager.Get(OctreeType.Nodule));
        var noduleRate = NoduleSensor.RefreshRate;

        NoduleSensor.RefreshRate += Random.Range(-.05f * noduleRate, .05f * noduleRate);

        base.OnStartServer();
    }
    private void CalculateColliderAcitvationRange()
    {
        var boundingRadius = GetBoundingSphereRadius();

        GetComponent <SphereCollider>().radius = boundingRadius + CubeInteractionRadius;
        InteractableCollider.Radius            = boundingRadius;

        if (OctreeManager.Get(OctreeType.Player) != null)
        {
            var colliders = OctreeManager.Get(OctreeType.Player).GetObjectsInRange(transform.position, boundingRadius + CubeInteractionRadius);

            TriggeredCount = colliders.Length;
            EvaluateTriggeredCount();
        }
    }
예제 #6
0
    public GameObject SpawnCarnivore(Vector3 pos, Quaternion rot, CarnivoreType type)
    {
        var carn = CarnivoreFactory.InstantiateCarnivore(pos, rot, type);

        carn.transform.SetParent(transform);
        NetworkServer.Spawn(carn.gameObject);

        if (!m_Carnivores.ContainsKey(type))
        {
            m_Carnivores.Add(type, new HashSet <CarnivoreBase>());
        }

        m_Carnivores[type].Add(carn);
        OctreeManager.Get(OctreeType.Carnivore).Add(carn.transform);
        return(carn.gameObject);
    }
예제 #7
0
    public GameObject SpawnHerbivore(Vector3 pos, Quaternion rot, HerbivoreType type)
    {
        var herb = HerbivoreFactory.InstantiateHerbivore(pos, rot, type);

        herb.transform.SetParent(transform);
        NetworkServer.Spawn(herb.gameObject);

        if (!m_Herbivores.ContainsKey(type))
        {
            m_Herbivores.Add(type, new HashSet <HerbivoreBase>());
        }

        m_Herbivores[type].Add(herb);
        OctreeManager.Get(OctreeType.Herbivore).Add(herb.transform);
        return(herb.gameObject);
    }
예제 #8
0
    public void KillCarnivore(CarnivoreBase carn, bool predation = false)
    {
        if (carn == null || carn.gameObject == null)
        {
            return;
        }

        if (m_Carnivores.ContainsKey(carn.Type))
        {
            m_Carnivores[carn.Type].Remove(carn);
        }

        OctreeManager.Get(OctreeType.Carnivore).Remove(carn.transform);

        if (predation && OnPredationEvent != null)
        {
            OnPredationEvent(carn);
        }

        NetworkServer.Destroy(carn.gameObject);

        ValidateCarnivoreCount();
    }
예제 #9
0
    public void KillHerbivore(HerbivoreBase herb, bool predation = false)
    {
        if (herb == null || herb.gameObject == null)
        {
            return;
        }

        if (m_Herbivores.ContainsKey(herb.Type))
        {
            m_Herbivores[herb.Type].Remove(herb);
        }

        OctreeManager.Get(OctreeType.Herbivore).Remove(herb.transform);

        if (predation && OnPredationEvent != null)
        {
            OnPredationEvent(herb);
        }

        NetworkServer.Destroy(herb.gameObject);

        ValidateHerbivoreCount();
    }
예제 #10
0
    private void AvoidPlayerUpdate()
    {
        m_CheckForPlayerCounter += Time.deltaTime;
        if (m_CheckForPlayerCounter > CheckForPlayerRate)
        {
            m_CheckForPlayerCounter = 0f;
            var closestPlayer = OctreeManager.Get(OctreeType.Player).GetClosestObject(transform.position);

            var vectorToStart = (new Vector3(m_StartPos.x, transform.position.y, m_StartPos.z) - transform.position).normalized * FloatSpeed;

            //Make sure there is a player in range
            if (closestPlayer != null &&
                (closestPlayer.position - transform.position).sqrMagnitude < CheckForPlayerRange * CheckForPlayerRange)
            {
                var evadeVector = Steering.Evade(gameObject, closestPlayer.gameObject, FloatSpeed);

                //Go to start XZ pos if that is close to the evade vector
                m_FloatVel = Vector3.Angle(evadeVector, vectorToStart) < 90f
                            ? new Vector3(vectorToStart.x, m_FloatVel.y, vectorToStart.z)
                            : new Vector3(evadeVector.x, m_FloatVel.y, evadeVector.z);

                return;
            }

            //Are we not close to our starting position on the horizontal plane
            if ((transform.position - new Vector3(m_StartPos.x, transform.position.y, m_StartPos.z)).sqrMagnitude > 2f)
            {
                //Float towards start on the horizontal
                m_FloatVel = new Vector3(vectorToStart.x, m_FloatVel.y, vectorToStart.z);
            }
            else
            {
                m_FloatVel = new Vector3(0, m_FloatVel.y, 0);
            }
        }
    }
예제 #11
0
    private void CheckForPlayer()
    {
        var player = OctreeManager.Get(OctreeType.Player).GetClosestObject(transform.position, m_InteractionRadius);

        ProximityShrink(player);
    }
예제 #12
0
    public override void OnStartServer()
    {
        m_AnimAudioController = GetComponent <TriHorseAnimAudioController>();
        m_AnimAudioController.OnEatingFinished += OnEatingFinished;
        m_AnimAudioController.OnDyingFinished  += Die;

        Grower = new ScaledGrowth(transform,
                                  DataStore.GetFloat(Data.TriHorseInitialScale),
                                  DataStore.GetFloat(Data.TriHorseFinalScaleMin),
                                  DataStore.GetFloat(Data.TriHorseFinalScaleMax));

        Grower.StartGrowing();
        Scale = Grower.Scale;

        AgeData.DaysToGrown = DataStore.GetFloat(Data.TriHorseDaysToGrown);
        AgeData.LifeSpan    = DataStore.GetFloat(Data.TriHorseLifeSpan);
        BaseSpeed           = DataStore.GetFloat(Data.TriHorseBaseSpeed);

        DaysBeforeReproducing          = DataStore.GetFloat(Data.TriHorseDaysBeforeReproducing);
        DaysBetweenReproductions       = DataStore.GetFloat(Data.TriHorseDaysBetweenReproductions);
        StarvingDamageAmount           = DataStore.GetFloat(Data.TriHorseStarvingDamageAmount);
        StructureCollisionDamageAmount = DataStore.GetFloat(Data.TriHorseStructureCollisionDamageAmount);
        SensingRadius = DataStore.GetFloat(Data.TriHorseSensingRadius);

        WanderParameters.Radius              = DataStore.GetFloat(Data.TriHorseWanderRadius);
        WanderParameters.Distance            = DataStore.GetFloat(Data.TriHorseWanderDistance);
        WanderParameters.Jitter              = DataStore.GetFloat(Data.TriHorseWanderJitter);
        FlockingOptions.WanderWeight         = DataStore.GetFloat(Data.TriHorseWanderWeight);
        FlockingOptions.AlignmentWeight      = DataStore.GetFloat(Data.TriHorseAlignWeight);
        FlockingOptions.MinDispersion        = DataStore.GetFloat(Data.TriHorseMinFlockDispersion);
        FlockingOptions.MaxDispersion        = DataStore.GetFloat(Data.TriHorseMaxFlockDispersion);
        FlockingOptions.MinDispersionSquared = FlockingOptions.MinDispersion * FlockingOptions.MinDispersion;
        FlockingOptions.MaxDispersionSquared = FlockingOptions.MaxDispersion * FlockingOptions.MaxDispersion;

        m_FlockmateSensor             = new OctreeSensor <TriHorse>(transform, SensingRadius, 20, OctreeManager.Get(OctreeType.Herbivore));
        m_FlockmateSensor.RefreshRate = m_FlockmateSensor.RefreshRate.Randomize(.05f);

        base.OnStartServer();
        Scale = Grower.Scale;

        BehaviourBrain.In(BehaviourState.SeekingFood)
        .If(() => Health <= 0)
        .GoTo(BehaviourState.Death)
        .If(() => m_InDeathThrows)
        .GoTo(BehaviourState.Dying)
        .If(() => m_TimeSinceEating < DayClock.Singleton.DaysToSeconds(.4f))
        .GoTo(BehaviourState.Flocking)
        .If(CanReproduce)
        .GoTo(BehaviourState.Reproducing)
        .If(() => m_EatingNodule)
        .GoTo(BehaviourState.Eating)
        .ExecuteWhileIn(SeekFood, StarvationCheck);

        BehaviourBrain.In(BehaviourState.Flocking)
        .If(() => Health <= 0)
        .GoTo(BehaviourState.Death)
        .If(() => m_InDeathThrows)
        .GoTo(BehaviourState.Dying)
        .If(() => m_TimeSinceEating > DayClock.Singleton.DaysToSeconds(.4f))
        .GoTo(BehaviourState.SeekingFood)
        .If(CanReproduce)
        .GoTo(BehaviourState.Reproducing)
        .ExecuteWhileIn(Flocking);

        BehaviourBrain.In(BehaviourState.Eating)
        .If(() => m_InDeathThrows)
        .GoTo(BehaviourState.Dying)
        .If(() => !m_EatingNodule)
        .GoTo(BehaviourState.Flocking)
        .ExecuteOnEntry(StartEating)
        .ExecuteWhileIn(EatNodule)
        .ExecuteOnExit(EndEating);

        BehaviourBrain.In(BehaviourState.Reproducing)
        .DoOnce(Reproduce)
        .If(() => true)
        .GoTo(BehaviourState.SeekingFood);

        //Empty state. All action is handled through anim callbacks or outside function calls
        //Once we enter this state, we do not leave it.
        BehaviourBrain.In(BehaviourState.Dying);

        BehaviourBrain.In(BehaviourState.Death)
        .DoOnce(Die);

        BehaviourBrain.Initialize(BehaviourState.SeekingFood);

        //This forces the herbivore to start in the seeking food state
        m_TimeSinceEating = DayClock.Singleton.DaysToSeconds(.4f);
    }
예제 #13
0
    private IEnumerator InitializePlayerSensor()
    {
        while (!OctreeManager.Contains(OctreeType.Player))
        {
            yield return(new WaitForSeconds(.5f));
        }

        m_PlayerSensor = new OctreeSensor <Transform>(transform, CalculateEnclosingRadius(), OctreeManager.Get(OctreeType.Player))
        {
            RefreshRate = .1f.Randomize(.05f)
        };
    }
 private void Start()
 {
     if (isServer)
         m_PlayerSensor = new OctreeSensor<NetworkIdentity>(OriginTransform, m_InteractRange, OctreeManager.Get(OctreeType.Player))
         {
             RefreshRate = .1f.Randomize(.03f)
         };
 }
    protected override void Start()
    {
        Rigidbody = GetComponent <Rigidbody>();

        base.Start();

        if (!isServer && isClient)
        {
            var anim = GetComponent <Animator>();
            if (anim != null)
            {
                anim.applyRootMotion = false;
            }
            return;
        }

        if (!isServer)
        {
            return;
        }

        HerbivoreSensor = new OctreeSensor <HerbivoreBase>(transform, SensingRadius, MaximumHerdSizeToAttack + 1, OctreeManager.Get(OctreeType.Herbivore));

        //Starts the carnivore slightly hungry
        TimeSinceEating = DayClock.Singleton.DaysToSeconds(1.01f);
    }
    private void CheckForPlayer()
    {
        var player = OctreeManager.Get(OctreeType.Player).GetClosestObject(transform.position, m_InteractionRadius);

        SetState(player == null ? State.Inactive : State.Active);
    }
예제 #17
0
 private void Start()
 {
     m_Sensor = new OctreeSensor <Transform>(transform, Range, 1, OctreeManager.Get(OctreeType.Player));
 }