Ejemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     player          = GameObject.FindWithTag("Player");
     playerInput     = player.GetComponent <PlayerInput>();
     playerResources = player.GetComponent <PlayerResources>();
     zoneGenerator   = GameObject.Find("World").GetComponent <ZoneGenerator>();
 }
 protected bool AttemptGen(int stepNum, ZoneGenerator zoneGen)
 {
     if (!(column_uses[stepNum].ContainsKey(zoneGen.activationKey) && zoneGen.maxColumnActivations <= column_uses[stepNum][zoneGen.activationKey]) && !(total_uses.ContainsKey(zoneGen.activationKey) && zoneGen.maxWorldActivations <= total_uses[zoneGen.activationKey]))
     {
         if (zoneGen is PostProcessZoneGenerator)
         {
             var   gen  = zoneGen as PostProcessZoneGenerator;
             float prob = probabilities.ContainsKey(gen) ? probabilities[gen] : gen.probability;
             if (prob >= bar.runCtrl.NextWorldRand(0, 100))
             {
                 if (!probabilities.ContainsKey(gen))
                 {
                     probabilities.Add(gen, gen.probability);
                 }
                 probabilities[gen] /= gen.probabilityReductionFactor;
                 return(true);
             }
             else if (gen.probabilityReductionOnFail)
             {
                 if (!probabilities.ContainsKey(gen))
                 {
                     probabilities.Add(gen, gen.probability);
                 }
                 probabilities[gen] /= gen.probabilityReductionFactor;
             }
         }
         else
         {
             return(true);
         }
     }
     return(false);
 }
    public ZoneDot CreatePrevDot(ZoneDot dot, ZoneGenerator gen, bool add = true)
    {
        var newDot = CreateDot(dot.stepNum + 1, gen);

        if (add)
        {
            AddBefore(newDot, dot);
        }
        return(newDot);
    }
    public ZoneDot CreateNextDot(ZoneDot dot, ZoneGenerator gen, bool add = true)
    {
        var newDot = CreateDot(dot.stepNum + 1, gen);

        if (add)
        {
            AddAfter(newDot, dot);
        }
        return(newDot);
    }
Ejemplo n.º 5
0
 void Awake()
 {
     if (instance != null && instance != this)
     {
         Destroy(gameObject);
     }
     else
     {
         instance = this;
     }
 }
    public ZoneDot CreateDot(int index1, ZoneGenerator gen)
    {
        RectTransform rectTransform = columnTransforms[index1];
        ZoneDot       zoneDot       = UnityEngine.Object.Instantiate <ZoneDot>(bar.zoneDotPrefab, bar.transform.position, bar.transform.rotation, rectTransform.transform);

        zoneDot.stepNum         = index1;
        zoneDot.worldBar        = bar;
        zoneDot.idCtrl          = bar.idCtrl;
        zoneDot.btnCtrl         = bar.btnCtrl;
        zoneDot.transform.name  = "ZoneDot - Step: " + (object)index1;
        zoneDot.verticalSpacing = bar.defaultVerticalSpacing + gen.verticalSpacing;
        var step = bar.currentZoneSteps[index1];

        if (!gen.addFirst)
        {
            step.Add(zoneDot);
        }
        else
        {
            step.Insert(0, zoneDot);
        }
        bar.currentZoneDots.Add(zoneDot);
        if (gen.relativeTransforms)
        {
            if (step.Count == 1)
            {
                zoneDot.transform.position = rectTransform.position;
            }
            else
            {
                if (gen.addFirst)
                {
                    zoneDot.transform.position = step[1].transform.position + new Vector3(0.0f, zoneDot.verticalSpacing * bar.rect.localScale.y, 0.0f);
                }
                else
                {
                    zoneDot.transform.position = step[step.Count - 2].transform.position - new Vector3(0.0f, zoneDot.verticalSpacing * bar.rect.localScale.y, 0.0f);
                }
            }
        }
        else
        {
            for (int i = 0; i < step.Count; i++)
            {
                var dot = step[i];
                dot.transform.localPosition = new Vector3(0.0f, ((float)(step.Count - 1) / 2f - (float)(i)) * zoneDot.verticalSpacing * rectTransform.localScale.y, 0.0f);
            }
        }


        if (gen.zoneType == ZoneType.World && gen is ManualZoneGenerator)
        {
            ManualZoneGenerator manual = (ManualZoneGenerator)gen;
            //Default world stuff
            if (manual.automaticWorldSelection)
            {
                if (stringList.Count > 0)
                {
                    int index3 = bar.runCtrl.NextWorldRand(0, stringList.Count);
                    zoneDot.worldName = stringList[index3];
                    stringList.Remove(stringList[index3]);
                }
                else
                {
                    if (bar.runCtrl.currentRun.bossExecutions >= 7)
                    {
                        zoneDot.worldName = "Genocide";
                        zoneDot.imageName = "WorldWasteland";
                    }
                    else if (bar.runCtrl.currentRun.bossExecutions >= 1)
                    {
                        zoneDot.worldName = "Normal";
                        zoneDot.imageName = "WorldWasteland";
                    }
                    else
                    {
                        zoneDot.worldName = "Pacifist";
                        zoneDot.imageName = "WorldWasteland";
                    }
                }
                zoneDot.world     = bar.runCtrl.worlds[zoneDot.worldName];
                zoneDot.imageName = zoneDot.world.iconName;
            }
        }
        EditDotWithGen(zoneDot, gen);

        return(zoneDot);
    }
    protected void EditDotWithGen(ZoneDot dot, ZoneGenerator zoneGen)
    {
        if (zoneGen.zoneType == ZoneType.World && !(zoneGen is ManualZoneGenerator && ((ManualZoneGenerator)zoneGen).automaticWorldSelection))
        {
            try
            {
                dot.world     = bar.runCtrl.worlds[zoneGen.worldName];
                dot.worldName = zoneGen.worldName;
                dot.imageName = dot.world.iconName;
                if (zoneGen.refreshCurrentworld)
                {
                    refreshWorldDots.Add(dot);
                }
                else
                {
                    refreshWorldDots.Remove(dot);
                }
            }
            catch
            {
                Debug.LogError("No world exists with name: " + zoneGen.worldName);
            }
        }
        else if (dot.type == ZoneType.World)
        {
            refreshWorldDots.Remove(dot);
        }
        if (zoneGen.dark)
        {
            dot.SetDark();
        }
        dot.SetType(zoneGen.zoneType);
        if (source.ContainsKey(dot))
        {
            source[dot] = zoneGen;
        }
        else
        {
            source.Add(dot, zoneGen);
        }

        if (!column_uses.ContainsKey(dot.stepNum))
        {
            column_uses.Add(dot.stepNum, new Dictionary <string, int>());
        }

        if (!column_uses[dot.stepNum].ContainsKey(zoneGen.activationKey))
        {
            column_uses[dot.stepNum].Add(zoneGen.activationKey, 1);
        }
        column_uses[dot.stepNum][zoneGen.activationKey]++;
        if (!total_uses.ContainsKey(zoneGen.activationKey))
        {
            total_uses.Add(zoneGen.activationKey, 1);
        }
        total_uses[zoneGen.activationKey]++;

        if (invisDots.ContainsKey(dot))
        {
            var key = invisDots[dot];
            if (hiddenSections.ContainsKey(key))
            {
                hiddenSections[key].Remove(dot);
                if (dot.image != null)
                {
                    dot.image.enabled = true;
                }
                if (dot.fgImage != null)
                {
                    dot.fgImage.enabled = true;
                }
                if (dot.bgImage != null)
                {
                    dot.bgImage.enabled = true;
                }
            }
        }
    }
Ejemplo n.º 8
0
        static async Task Main(string[] args)
        {
            var serilogger = new LoggerConfiguration()
                             .WriteTo.File("log.txt", rollingInterval: RollingInterval.Day)
                             .CreateLogger();
            var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder
                // .AddFilter("Microsoft", LogLevel.Warning)
                // .AddFilter("System", LogLevel.Warning)
                // .AddFilter("LoggingConsoleApp.Program", LogLevel.Debug)
                .AddSerilog(serilogger)
                .AddConsole();
            });

            _logger = loggerFactory.CreateLogger <Program>();

            // Register extensions to Json.NET Serialization
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Converters = new List <JsonConverter>
                {
                    new MathJsonConverter(),
                    Converter.DateTimeConverter,
                    Converter.BinaryConverter,
                    Converter.GroupingConverter,
                    Converter.PocoExprConverter
                }
            };
            Converter.Serializer.Converters.Add(new MathJsonConverter());

            // Register extensions to MessagePack Serialization
            var resolver = CompositeResolver.Create(
                MathResolver.Instance,
                NativeGuidResolver.Instance,
                StandardResolver.Instance
                );
            var options = MessagePackSerializerOptions.Standard.WithResolver(resolver);

            MessagePackSerializer.DefaultOptions = options;

            var connection = R.Connection().Hostname("asgard.gamecult.games")
                             .Port(RethinkDBConstants.DefaultPort).Timeout(60).Connect();

            var cache = new DatabaseCache();

            // When entries are changed locally, push the changes to RethinkDB
            cache.OnDataUpdateLocal += async entry =>
            {
                var table  = entry.GetType().GetCustomAttribute <RethinkTableAttribute>()?.TableName ?? "Other";
                var result = await R.Db("Aetheria").Table(table).Update(entry).RunAsync(connection);

                _logger.Log(LogLevel.Information, $"Uploaded entry to RethinkDB: {entry.ID} result: {result}");
            };

            cache.OnDataInsertLocal += async entry =>
            {
                var table    = entry.GetType().GetCustomAttribute <RethinkTableAttribute>()?.TableName ?? "Other";
                var inserted = false;
                for (int i = 0; i < 5 && !inserted; i++)
                {
                    try
                    {
                        var result = await R.Db("Aetheria").Table(table).Insert(entry).RunAsync(connection);

                        _logger.Log(LogLevel.Information, $"Inserted entry to RethinkDB: {entry.ID} result: {result}");
                        inserted = true;
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, e.Message);
                    }
                }
                if (!inserted)
                {
                    _logger.LogError("Failed to insert after 5 attempts!");
                }
            };

            cache.OnDataDeleteLocal += async entry =>
            {
                var table  = entry.GetType().GetCustomAttribute <RethinkTableAttribute>()?.TableName ?? "Other";
                var result = await R.Db("Aetheria").Table(table).Get(entry.ID).Delete().RunAsync(connection);

                _logger.Log(LogLevel.Information, $"Deleted entry from RethinkDB: {entry.ID} result: {result}");
            };

            // Get data from RethinkDB
            await GetTable("Items", connection, cache);
            await GetTable("Galaxy", connection, cache);
            await GetTable("Users", connection, cache);

            // Subscribe to changes from RethinkDB
            SubscribeTable("Items", connection, cache);
            SubscribeTable("Galaxy", connection, cache);
            SubscribeTable("Users", connection, cache);

            var server = new MasterServer(cache)
            {
                Logger = _logger
            };

            server.Start();

            var context = new GameContext(cache, s => _logger.Log(LogLevel.Information, s));

            context.MapLayers = cache.GetAll <GalaxyMapLayerData>().ToDictionary(m => m.Name);

            server.AddMessageListener <GalaxyRequestMessage>(galaxyRequest => galaxyRequest.Peer.Send(
                                                                 new GalaxyResponseMessage
            {
                Zones = cache.GetAll <ZoneData>().Select(zd =>
                                                         new GalaxyResponseZone
                {
                    Name     = zd.Name,
                    Position = zd.Position,
                    ZoneID   = zd.ID,
                    Links    = zd.Wormholes?.ToArray() ?? Array.Empty <Guid>()
                }).ToArray(),
                GlobalData  = context.GlobalData,
                StarDensity = context.MapLayers["StarDensity"]
            }));

            server.AddMessageListener <BlueprintsRequestMessage>(blueprintRequest => blueprintRequest.Peer.Send(
                                                                     new BlueprintsResponseMessage
            {
                Blueprints = cache.GetAll <BlueprintData>().ToArray()
            }));

            server.AddMessageListener <ZoneRequestMessage>(zoneRequest =>
            {
                var zone = cache.Get <ZoneData>(zoneRequest.ZoneID);

                // Zone has not been populated, generate the contents now!
                if (!zone.Visited)
                {
                    zone.Visited = true;
                    OrbitData[] orbits;
                    PlanetData[] planets;
                    ZoneGenerator.GenerateZone(
                        global: context.GlobalData,
                        zone: zone,
                        mapLayers: context.MapLayers.Values,
                        resources: cache.GetAll <SimpleCommodityData>().Where(i => i.ResourceDensity.Any()),
                        orbitData: out orbits,
                        planetsData: out planets);
                    cache.AddAll(orbits);
                    cache.AddAll(planets);
                    cache.Add(zone);
                }
                zoneRequest.Peer.Send(
                    new ZoneResponseMessage
                {
                    Zone     = zone,
                    Contents = zone.Orbits.Select(id => cache.Get(id))
                               .Concat(zone.Planets.Select(id => cache.Get(id)))
                               .Concat(zone.Stations.Select(id => cache.Get(id))).ToArray()
                });
            });

            Observable.Timer(DateTimeOffset.Now, TimeSpan.FromSeconds(60)).SubscribeOn(NewThreadScheduler.Default).Subscribe(_ =>
            {
                _logger.Log(LogLevel.Information, R.Now().Run <DateTime>(connection).ToString() as string);
            });

            while (true)
            {
                Thread.Sleep(100);
            }
        }