예제 #1
0
            public static LuaResult require(ModuleScript module)
            {
                if (module.ReturnValue != null)
                {
                    return(module.ReturnValue);
                }

                var e = new StartExecution(module);

                try
                {
                    e.TryFulfill();

                    if (e.Result?.Count != 1)
                    {
                        throw new Exception("Module did not return exactly one value.");
                    }
                }
                catch (Exception exception)
                {
                    throw new Exception("Requested module experienced an error while loading", exception);
                }

                return(module.ReturnValue = e.Result);
            }
 public void RebuildModule(ModuleScript module)
 {
     foreach (var child in module.transform)
         Destroy((child as Transform).gameObject);
     module.ConnectionPoints.Clear();
     module.BuildModule(2);
 }
예제 #3
0
        internal static string Move(this CGameResult move, string current, ModuleScript moduleScript = null)
        {
            var str = new StringBuilder(current);

            // If the destination is occupied, this implies a capture.
            if (str[move.Destination] != '_' && moduleScript != null)
            {
                moduleScript.PlaySound(Sounds._1dch.Capture);
            }

            // Moves origin to destination, leaving origin empty.
            str[move.Destination] = str[move.Origin];
            str[move.Origin]      = '_';

            return(str.ToString());
        }
    public bool TryMoveToValidPosition(ModuleScript attachModule, GameObject connectionPoint)
    {
        List<GameObject> sisterPoints = attachModule.ConnectionPoints.Where(p => Vector3.Angle(connectionPoint.transform.forward, p.transform.forward) == 180).ToList();
        if (sisterPoints.Any())
        {
            foreach (var point in sisterPoints)
            {
                Vector3 goalCoords = GetDestinationCoords(connectionPoint);
                Vector3 offset = goalCoords - point.transform.position;
                Debug.Log(String.Format("Testing placement of {0} at {1}", attachModule.Module.Name, offset));
                if (!Floorplan.IsConflicting(attachModule.Module.Floorplan, offset.x, offset.z, offset.y))
                {
                    attachModule.transform.position = connectionPoint.transform.GetChild(0).position - point.transform.GetChild(0).position;
                    attachModule.ConnectionPoints.Remove(point);
                    return true;
                }
                else
                    Debug.Log("Placement conflicting");
            }
        }

        return false;
    }
예제 #5
0
 private static void Save(ModuleScript script, string newPath)
 {
     File.WriteAllBytes(Path.Combine(newPath, $"{GetShortendScriptName(script)}_{ RemoveInvalidFilePathCharacters(script.Name,'_') }[{script.ScriptGuid}].lua"), script.Source);
 }
예제 #6
0
 public static string GetShortendScriptName(ModuleScript script)
 {
     return("M");
 }
    void Start()
    {
        Instance = this;
        PlacedModules = new Dictionary<ModuleScript, Vector3>();
        unfinishedModules = new Queue<ModuleScript>();
        Floorplan = new Floorplan();

        //here, pick a level "format" or "rule set" and broadcast it to clients
        //this should be able to be passed in from the lobby
        //this is also probably the best place to pick and broadcast a random seed (or, again, accept one from the lobby)
        int seed = 0;
        //int seed = (int)DateTime.Now.Ticks;
        LevelRNG = new System.Random(seed);
        Debug.Log("Seed:" + seed);
        Level = Level.ReadRulesXML("");

        Vector3 position = new Vector3(0, 0, 0);
        RootModule = Instantiate(ModuleContainerPrefab, position, Quaternion.identity) as ModuleScript;
        RootModule.Module = Level.RootModule;

        RootModule.BuildModule(2);
        PlacedModules.Add(RootModule, position);
        Floorplan.Merge(RootModule.Module.Floorplan, 0, 0, 0);

        unfinishedModules.Enqueue(RootModule);
    }