Exemple #1
0
    public override void Initialize(Transform[] objects)
    {
        // list because I don't know size here
        List <Filter> tmpFilters = new List <Filter>();
        int           index      = 0;

        for (int i = 0; i < objects.Length; i++)
        {
            // check performance
            GameManagerComponent gmc = objects[i].GetComponent <GameManagerComponent>();

            if (gmc)
            {
                tmpFilters.Add(new Filter(index, objects[i].gameObject, gmc));
                gmc.OnRestart += Restart;
                gmc.OnVictory += VictoryScreen;
                //gmc.OnDeath += RestartFromDeath;

                gmc.OnStartGameTick += StartGameTick;
                gmc.OnStopGameTick  += StopGameTick;
            }
        }

        filters                = tmpFilters.ToArray();
        travelComponent        = GetComponentInChildren <TravelComponent>();
        transportableComponent = GetComponentInChildren <CartComponent>();
        goapSystem             = GetComponent <GOAPSystem>();
    }
    public override void Initialize(Transform[] objects)
    {
        // list because I don't know size here
        List <Filter> tmpFilters = new List <Filter>();
        int           index      = 0;

        for (int i = 0; i < objects.Length; i++)
        {
            // check performance
            InventoryComponent  invC = objects[i].GetComponent <InventoryComponent>();
            InputComponent      inpC = objects[i].GetComponent <InputComponent>();
            InteractorComponent intC = objects[i].GetComponent <InteractorComponent>();
            MovementComponent   movC = objects[i].GetComponent <MovementComponent>();

            if (invC && inpC && intC && movC)
            {
                tmpFilters.Add(new Filter(index, objects[i].gameObject, invC, inpC, intC, movC));
            }
        }

        filters = tmpFilters.ToArray();

        environmentComponent   = GetComponentInChildren <EnvironmentComponent>();
        transportableComponent = GetComponentInChildren <CartComponent>();
        cartInteractable       = transportableComponent.GetComponent <InteractableComponent>();
        lightComponent         = GetComponentInChildren <LightComponent>();
        //villagerComponent = GetComponentInChildren<VillagerComponent>();
        travelComponent  = GetComponentInChildren <TravelComponent>();
        treeComponents   = GetComponentsInChildren <CollectibleComponent>();
        goapSystem       = GetComponent <GOAPSystem>();
        navMeshComponent = playerGO.GetComponent <NavMeshComponent>();
    }
        private void ProcessMove(Entity entity, JToken jToken)
        {
            if (jToken["destination"] == null)
            {
                return;
            }

            var travel    = entity.GetComponent <TravelComponent>();
            var placement = entity.GetComponent <PlacementComponent>();

            if (placement == null)
            {
                //send error
                Console.WriteLine("no placement on player");
                return;
            }

            var lastLocation = travel == null ? placement.Location : travel.Route.Last();
            LocationComponent newLocation = null;

            foreach (var road in lastLocation.Roads)
            {
                if (road.To.Id != jToken["destination"].Value <int>())
                {
                    continue;
                }
                newLocation = road.To;
                break;
            }

            if (newLocation == null)
            {
                //send error
                Console.WriteLine("no way to this location");
                return;
            }
            if (travel == null)
            {
                travel = new TravelComponent
                {
                    Status = TravelComponent.TravelingStatus.Starting,
                    Route  = { newLocation }
                };
                entity.AddComponent(travel);
            }
            else
            {
                travel.Route.Add(newLocation);
            }
        }