Пример #1
0
        public void render()
        {
            for (int x = 0; x < tiles.GetLength(0); x++)
            {
                for (int y = 0; y < tiles.GetLength(1); y++)
                {
                    Engine.Engine.Draw(tiles[x, y].GetSprite(), new IntVec(x, y));
                }
            }

            Environment.Draw();
            //drawAStar();
            InteractableEnvironment.Draw();

            DroppedItems.Draw();
            LightSources.Draw();
            CharacterEntities.Draw();

            //CharacterEntities.InvokeOnAll( (GameCharacter character, IntVec position) =>
            //{
            //    position.X += character.GetSprite().Direction.X;
            //    position.Y += character.GetSprite().Direction.Y;
            //});

            //foreach (var pair in CharacterEntities.Tuples())
            //{
            //    pair.Item2.X += pair.Item1.GetSprite().Direction.X;
            //    pair.Item2.Y += pair.Item1.GetSprite().Direction.Y;
            //}
        }
Пример #2
0
        private void cache()
        {
            if (needToCache)
            {
                for (int x = 0; x < tiles.GetLength(0); x++)
                {
                    for (int y = 0; y < tiles.GetLength(1); y++)
                    {
                        cachedSolid[x, y] = tiles[x, y].isSolid;
                    }
                }

                foreach (IntVec position in CharacterEntities.Positions())
                {
                    cachedSolid[position.X, position.Y] = true;
                }

                foreach (Tuple <IEnvironmentObject, IntVec> enviro in Environment.Tuples())
                {
                    cachedSolid[enviro.Item2.X, enviro.Item2.Y] |= enviro.Item1.IsSolid();
                }

                foreach (Tuple <IInteractable, IntVec> enviro in InteractableEnvironment.Tuples())
                {
                    cachedSolid[enviro.Item2.X, enviro.Item2.Y] |= enviro.Item1.IsSolid();
                }

                foreach (Tuple <ILightSource, IntVec> enviro in LightSources.Tuples())
                {
                    //cachedSolid[enviro.Item2.X, enviro.Item2.Y] = true;
                }
                needToCache = false;
            }
        }
Пример #3
0
 public MainGameEntity(Data.MainGameData mainGameData)
 {
     foreach (var data in mainGameData.CharacterDatas)
     {
         CharacterEntities.Add(new CharacterEntity(data));
     }
     PlayerEntity = new PlayerEntity(mainGameData.PlayerData);
 }
Пример #4
0
 public IEnumerable <GameCharacter> GetCharactersIsFriendly(bool isFriendly)
 {
     foreach (GameCharacter character in CharacterEntities.Entities())
     {
         if (character.isFriendly == isFriendly)
         {
             yield return(character);
         }
     }
 }
Пример #5
0
        public bool Move(GameCharacter character, IntVec position, bool absolute = false)
        {
            bool moveWasMade = false;

            if (absolute && !isSolid(position))
            {
                moveWasMade = CharacterEntities.SetPosition(character, position);
            }
            else
            if (!absolute && !isSolid(CharacterEntities.FindPosition(character) + position))
            {
                moveWasMade = CharacterEntities.AddPosition(character, position);
            }
            return(moveWasMade);
        }
Пример #6
0
        public int[,] getIntSolid(bool treatCharactersSolid = true)
        {
            cache();

            int[,] result = new int[cachedSolid.GetLength(0), cachedSolid.GetLength(1)];

            for (int x = 0; x < result.GetLength(0); x++)
            {
                for (int y = 0; y < result.GetLength(1); y++)
                {
                    result[x, y] = (cachedSolid[x, y]) ? int.MaxValue : int.MinValue;
                }
            }

            if (!treatCharactersSolid)
            {
                foreach (IntVec vec in CharacterEntities.Positions())
                {
                    result[vec.X, vec.Y] = int.MinValue;
                }
            }

            return(result);
        }
Пример #7
0
    /// <summary>Used internally - don't call this one. Startup the UI for use in the Editor with AOT Nitro.</summary>
    /// <param name="nitroAot">True if no gameobject should be generated.</param>
    public static void Start(bool nitroAot)
    {
        if (_Started)
        {
            return;
        }

        _Started = true;

        // Setup atlas stacks:
        AtlasStacks.Start();

        // Hookup the wrench logging method:
        Dom.Log.OnLog += OnLogMessage;

        // Hookup the InfiniText logging method:
        InfiniText.Fonts.OnLog += OnLogMessage;

                #if !NoBIDI
        // Setup bidi character metadata:
        InfiniText.DirectionCategory.Setup();
                #endif

        // Setup the character entities such as &nbsp;
        CharacterEntities.Setup();

        // Start modules now! UI is always available so we use that:
        Modular.Start.Now(typeof(UI));

        // Setup language metadata:
        Languages.globalLoader.Setup();

        // Setup alert/confirm dialogues:
        BlockingDialogues.Setup();

        // Setup input:
        PowerUI.Input.Setup();

        // Setup the text/language service:
        if (Variables == null)
        {
            Variables = new FullVariableSet();

            if (!nitroAot)
            {
                // Sign up to the variable on change event - whenever a custom var is changed, we need to refresh the screen.
                Variables.OnChange += OnVariableChange;
                // Sign on to the event that occurs when the language changes.
                Dom.Text.OnLanguageChanged += OnLanguageChange;
                // Sign on to the event that occurs when the gender changes.
                Dom.Text.OnGenderChanged += ResolveAllVariables;
            }
        }

        // Setup the callback queue:
        Callbacks.Start();

        // Setup the character providers (for e.g. Emoji):
        CharacterProviders.Setup();

        Layer = LayerMask.NameToLayer("PowerUI");

                #if !NO_LAYER_CHECK
        if (Layer < 0)
        {
            // Invalid layer.
                        #if UNITY_EDITOR
            // Create the new layer now (this will actually be a permanent change):
            Layer = PowerUI.LayerManager.Add();
                        #else
            // On device - make one up:
            Layer = 21;
                        #endif
        }
                #endif

        // Default FPS:
        SetRate(DefaultRate);

                #if !NoNitroRuntime
        // Link up the text/javascript type by creating the engine:
        ScriptEngines.Add(new JavaScriptEngine());
                #endif

        if (nitroAot)
        {
            return;
        }

        GUINode = GameObject.Find("#PowerUI");

        if (GUINode == null)
        {
            // Not started yet.

            // Create the UI game object:
            GUINode      = new GameObject();
            GUINode.name = "#PowerUI";

            // Create the camera:
            CameraNode      = new GameObject();
            CameraNode.name = "Camera";

            // Create the updater:
            GlobalUpdater = GUINode.AddComponent <StandardUpdater>();

            // Setup the camera:
            GUICamera = CameraNode.AddComponent <Camera>();

            // Apply the new settings to the camera:
            GUICamera.orthographic = (CurrentCameraMode == CameraMode.Orthographic);
        }
        else
        {
            // Already started, but we might have updated.

            if (CameraNode == null)
            {
                // This can happen if the PowerUI assembly is actively reloaded (e.g. runtime updates).
                CameraNode      = GameObject.Find("#PowerUI/Camera");
                CameraTransform = CameraNode.transform;
                GUICamera       = CameraNode.GetComponent <Camera>();
            }
            else
            {
                // Already started!
                return;
            }
        }

        // Hide the PowerUI layer from all cameras other than GUICamera:
        Camera[] cameras = Camera.allCameras;

        int layerMask = ~(1 << UI.Layer);

        for (int i = 0; i < cameras.Length; i++)
        {
            // Grab the camera:
            Camera camera = cameras[i];

            // Is it the GUICamera?
            if (camera == GUICamera)
            {
                continue;
            }

            // Hide the UI layer from it:
            camera.cullingMask &= layerMask;
        }

        // Setup the transform:
        CameraTransform        = CameraNode.transform;
        CameraTransform.parent = GUINode.transform;

        GUICamera.nearClipPlane = 0.2f;
        GUICamera.depth         = CameraDepth;
        GUICamera.clearFlags    = CameraClearFlags.Depth;
        GUICamera.cullingMask   = (1 << UI.Layer);
        GUICamera.renderingPath = RenderingPath.Forward;

        SetCameraDistance(60f);
        SetFieldOfView(60f);

        Renderer = new Renderman();

        // Render Mesh.OutputGameObject with the GUI camera:
        Renderer.RenderWithCamera(UI.Layer);
        document            = Renderer.RootDocument as HtmlDocument;
        document.window.top = document.window;

        // Fire the camera event:
        CameraGotCreated(GUICamera);
    }
Пример #8
0
        internal void testUpdate()
        {
#if DEBUG
            if (MouseController.RightClicked())
            {
                IntVec pos = MouseController.MouseGridPosition();
                if (KeyboardController.IsDown('8'))
                {
                    Item[] items = new Item[statRand.Next(2, 8)];
                    for (int i = 0; i < items.Length; i++)
                    {
                        items[i] = Item.randomItem(DungeonLevel, 1);
                    }
                    InteractableEnvironment.Add(new Chest(items), pos);
                }

                if (KeyboardController.IsDown('9'))
                {
                    CharacterEntities.Add(Enemies.EnemyCreator.GetRandomEnemy(1, DungeonLevel)[0], pos);
                }

                if (KeyboardController.IsDown('0'))
                {
                    CharacterEntities.Add(Enemies.EnemyCreator.GetRandomBoss(DungeonLevel), pos);
                }
            }

            IntVec aMove = new IntVec((KeyboardController.IsTyped('H', 0) ? 1 : 0) - (KeyboardController.IsTyped('F', 0) ? 1 : 0), (KeyboardController.IsTyped('G', 0) ? 1 : 0) - (KeyboardController.IsTyped('T', 0) ? 1 : 0));
            IntVec bMove = new IntVec((KeyboardController.IsPressed('M') ? 1 : 0) - (KeyboardController.IsPressed('B') ? 1 : 0), (KeyboardController.IsPressed('N') ? 1 : 0) - (KeyboardController.IsPressed('J') ? 1 : 0));
            actionsToTake += (KeyboardController.IsDown('2') ? 1 : 0) - (KeyboardController.IsDown('1') ? 1 : 0);

            if (aMove.X != 0 || aMove.Y != 0 || bMove.X != 0 || bMove.Y != 0)
            {
                if (!isSolid(a + aMove))
                {
                    a += aMove;
                }

                if (!isSolid(b + bMove))
                {
                    b += bMove;
                }

                path = AStar.getPathBetween(this, a, b);

                actionsToTake = 1;

                int movement = Math.Abs(aMove.X) + Math.Abs(aMove.Y) + Math.Abs(bMove.X) + Math.Abs(bMove.Y);

                Engine.Engine.Log(string.Format("New A* path length: {0}", path.Length.ToString()));
                if (previousPathDistance != -1 && Math.Abs(previousPathDistance - path.Length) > movement)
                {
                    Engine.Engine.Log(string.Format("<INCONSISTENT PATHFIND; MOVEMENTDELTA={0},PATHDELTA={1}>", movement, Math.Abs(previousPathDistance - path.Length)));
                }

                //moveset = AStar.getTargetLine(this, startPoint, a, true);
                //moveset = AStar.getPossiblePositionsFrom(this, a, 15, AStar.CharacterTargeting.TARGET_FIRST, true);
                moveset = AStar.getPossiblePositionsInBox(this, a, 2, 2, AStar.CharacterTargeting.TARGET_FIRST, true);

                previousPathDistance = path.Length;
            }

            if (KeyboardController.IsPressed('Z'))
            {
                for (int i = 0; i < 100; i++)
                {
                    Item item = Item.getDesireditem(30, 30);

                    Engine.Engine.Log(string.Format("Item Generated: {0}", item.Name));

                    DroppedItems.Add(item, findRandomOpenPosition());
                }
            }

            if (KeyboardController.IsPressed('Q'))
            {
                for (int i = 0; i < 100; i++)
                {
                    Item item = Item.randomLegendary(30, 35);

                    Engine.Engine.Log(string.Format("Item Generated: {0}", item.Name));

                    DroppedItems.Add(item, findRandomOpenPosition());
                }
            }
#endif
        }