示例#1
0
 public static void DebugDrawPath(Vector2 from, List <Step> path)
 {
     if (path.Count > 0)
     {
         Debug.DrawLine(Iso.MapToWorld(from), Iso.MapToWorld(path[0].pos), Color.grey);
     }
     for (int i = 0; i < path.Count - 1; ++i)
     {
         Debug.DrawLine(Iso.MapToWorld(path[i].pos), Iso.MapToWorld(path[i + 1].pos));
     }
     if (path.Count > 0)
     {
         var center = Iso.MapToWorld(path[path.Count - 1].pos);
         Debug.DrawLine(center + Iso.MapToWorld(new Vector2(0, 0.15f)), center + Iso.MapToWorld(new Vector2(0, -0.15f)));
         Debug.DrawLine(center + Iso.MapToWorld(new Vector2(-0.15f, 0)), center + Iso.MapToWorld(new Vector2(0.15f, 0)));
     }
 }
示例#2
0
        void ControlCharacter()
        {
            if (player == null)
            {
                return;
            }

            DrawDebugPath();

            if (player.HandsItem != null)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Pickup.Create(player.transform.position, player.HandsItem);
                    FlushInput();
                    player.HandsItem = null;
                }
                return;
            }

            usingSkills = false;
            for (int i = 0; i < hotSkills.Count; ++i)
            {
                SkillInfo skill = hotSkills[i];
                KeyCode   key   = hotSkillsBindings[i];
                if (skill == null || !Input.GetKey(key))
                {
                    continue;
                }

                usingSkills = true;
                if (MouseSelection.instance.HotEntity != null)
                {
                    var targetCharacter = MouseSelection.instance.HotEntity.GetComponent <Character>();
                    if (targetCharacter != null)
                    {
                        player.character.UseSkill(skill, targetCharacter);
                    }
                    else
                    {
                        player.character.UseSkill(skill, Iso.MapToIso(MouseSelection.instance.HotEntity.transform.position));
                    }
                }
                else
                {
                    player.character.UseSkill(skill, IsoInput.mousePosition);
                }
            }

            if (!usingSkills)
            {
                if (Input.GetMouseButton(1) || (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButton(0)))
                {
                    player.character.UseSkill(rightSkill, IsoInput.mousePosition);
                }
                else if (Input.GetMouseButton(0))
                {
                    if (MouseSelection.instance.HotEntity != null)
                    {
                        var targetCharacter = MouseSelection.instance.HotEntity.GetComponent <Character>();
                        if (targetCharacter != null)
                        {
                            if (targetCharacter.monStat != null && targetCharacter.monStat.npc)
                            {
                                // todo interact with npc
                            }
                            else
                            {
                                player.character.UseSkill(leftSkill, targetCharacter);
                            }
                        }
                        else
                        {
                            player.character.Use(MouseSelection.instance.HotEntity);
                        }
                    }
                    else
                    {
                        player.character.GoTo(IsoInput.mousePosition);
                    }
                }
            }

            player.character.run = run;
        }
示例#3
0
        public static List <Step> BuildPath(Vector2 from_, Vector2 target_, float minRange = 0.1f, int size = 2, GameObject self = null, int depth = 100)
        {
            UnityEngine.Profiling.Profiler.BeginSample("BuildPath");
            Vector2i from = Iso.Snap(from_);

            target = Iso.Snap(target_);
            path.Clear();
            if (from == target)
            {
                UnityEngine.Profiling.Profiler.EndSample();
                return(path);
            }
            openNodes.Clear();
            Node.Recycle(closeNodes);

            Pathing.size = size;
            Pathing.self = self;
            Node startNode = Node.Get();

            startNode.parent         = null;
            startNode.pos            = from;
            startNode.gScore         = 0;
            startNode.hScore         = Vector2i.manhattanDistance(from, target);
            startNode.score          = int.MaxValue;
            startNode.directionIndex = -1;
            openNodes.Add(startNode);
            closeNodes.Add(startNode);
            int  iterCount = 0;
            Node bestNode  = startNode;

            while (openNodes.Count > 0)
            {
                Node node = openNodes.Take();

                if (node.hScore < bestNode.hScore)
                {
                    bestNode = node;
                }
                if (node.hScore <= minRange)
                {
                    TraverseBack(node);
                    break;
                }
                StepTo(node);
                iterCount += 1;
                if (iterCount > depth)
                {
                    TraverseBack(bestNode);
                    break;
                }
            }
            //foreach (Node node in closeNodes)
            //{
            //    Iso.DebugDrawTile(node.pos, Color.magenta, 0.3f);
            //}
            //foreach (Node node in openNodes)
            //{
            //    Iso.DebugDrawTile(node.pos, Color.green, 0.3f);
            //}
            UnityEngine.Profiling.Profiler.EndSample();
            return(path);
        }
示例#4
0
 public static void SetBlocked(Vector3 pos, CollisionLayers value)
 {
     SetBlocked(Iso.Snap(pos), value);
 }
示例#5
0
        void HandleKeyboard()
        {
            bool highlightPickups = Input.GetKey(KeyCode.LeftAlt) | Input.GetKey(KeyCode.RightAlt);

            MouseSelection.instance.SetHighlightPickups(highlightPickups);
            if (InventoryPanel.instance.visible || CharstatPanel.instance.visible)
            {
                if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Space))
                {
                    InventoryPanel.instance.visible = false;
                    CharstatPanel.instance.visible  = false;
                }
            }
            else if (Input.GetKeyDown(KeyCode.Escape))
            {
                GameMenu.Show();
            }

            if (!CommandPrompt.instance.visible)
            {
                if (Input.GetKeyDown(KeyCode.Return))
                {
                    CommandPrompt.instance.visible = true;
                }

                if (Input.GetKeyDown(KeyCode.I))
                {
                    InventoryPanel.instance.visible ^= true;
                }

                if (Input.GetKeyDown(KeyCode.C))
                {
                    CharstatPanel.instance.visible ^= true;
                }

                if (Input.GetKeyDown(KeyCode.R))
                {
                    run ^= true;
                }

                // following section serves debugging purposes only
                if (Input.GetKeyDown(KeyCode.T))
                {
                    for (int i = 0; i < 1; ++i)
                    {
                        var tc = TreasureClass.sheet[Random.Range(0, TreasureClass.sheet.Count)];
                        if (tc.name == null)
                        {
                            continue;
                        }
                        int itemLevel = Random.Range(50, 100);
                        ItemDrop.Drop(tc.name, Iso.MapToWorld(IsoInput.mouseTile), itemLevel);
                    }
                }
            }
            else
            {
                if (Input.GetKeyDown(KeyCode.Return))
                {
                    CommandPrompt.instance.visible = false;
                    CommandPrompt.instance.Execute();
                }

                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    CommandPrompt.instance.visible = false;
                }
            }
        }
示例#6
0
 public static bool Passable(Vector3 pos, CollisionLayers mask, int size = 1, GameObject ignore = null)
 {
     return(Passable(Iso.Snap(pos), mask, size, ignore));
 }
示例#7
0
 private int MapToIndex(Vector3 pos)
 {
     return(MapToIndex(Iso.Snap(pos)));
 }
示例#8
0
 public static void SetPassable(Vector3 pos, int sizeX, int sizeY, bool passable, GameObject gameObject)
 {
     SetPassable(Iso.Snap(pos), sizeX, sizeY, passable, gameObject);
 }
示例#9
0
        public void Use(MiscInfo itemInfo)
        {
            Debug.Log("Use item " + itemInfo.name + ", function: " + itemInfo.useFunction);
            switch (itemInfo.useFunction)
            {
            case MiscInfo.UseFunction.None:
                break;

            case MiscInfo.UseFunction.IdentifyItem:
                break;

            case MiscInfo.UseFunction.TownPortal:
                var pos      = Iso.MapToWorld(iso.pos);
                var teleport = WorldBuilder.SpawnObject("TP", pos, fit: true);
                teleport.modeName = "OP";
                var sound = SoundInfo.Find("player_townportal_cast");
                AudioManager.instance.Play(sound, pos);
                break;

            case MiscInfo.UseFunction.Potion:
                if (itemInfo.stat1 == "hpregen")
                {
                    character.health += itemInfo.calc1;
                }
                if (itemInfo.stat1 == "manarecovery")
                {
                    character.mana += itemInfo.calc1;
                }
                break;

            case MiscInfo.UseFunction.RejuvPotion:
                if (itemInfo.stat1 == "hitpoints")
                {
                    character.health += (int)(itemInfo.calc1 / 100.0f * character.maxHealth);
                }
                if (itemInfo.stat1 == "mana")
                {
                    character.mana += (int)(itemInfo.calc1 / 100.0f * character.maxMana);
                }
                if (itemInfo.stat2 == "hitpoints")
                {
                    character.health += (int)(itemInfo.calc2 / 100.0f * character.maxHealth);
                }
                if (itemInfo.stat2 == "mana")
                {
                    character.mana += (int)(itemInfo.calc2 / 100.0f * character.maxMana);
                }
                break;

            case MiscInfo.UseFunction.TemporaryPotion:
                break;

            case MiscInfo.UseFunction.HoradricCube:
                break;

            case MiscInfo.UseFunction.Elixir:
                break;

            case MiscInfo.UseFunction.StaminaPotion:
                break;
            }
        }
示例#10
0
        void ControlCharacter()
        {
            if (character == null)
            {
                return;
            }

            DrawDebugPath();

            if (_mouseItem != null)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Pickup.Create(character.transform.position, _mouseItem);
                    FlushInput();
                    mouseItem = null;
                }
                return;
            }

            usingSkills = false;
            for (int i = 0; i < hotSkills.Count; ++i)
            {
                SkillInfo skill = hotSkills[i];
                KeyCode   key   = hotSkillsBindings[i];
                if (skill == null || !Input.GetKey(key))
                {
                    continue;
                }

                usingSkills = true;
                if (MouseSelection.current != null)
                {
                    var targetCharacter = MouseSelection.current.GetComponent <Character>();
                    if (targetCharacter != null)
                    {
                        character.UseSkill(skill, targetCharacter);
                    }
                    else
                    {
                        character.UseSkill(skill, Iso.MapToIso(MouseSelection.current.transform.position));
                    }
                }
                else
                {
                    character.UseSkill(skill, IsoInput.mousePosition);
                }
            }

            // move to PlayerController members once Datasheets loading done not in static section
            SkillInfo leftSkill  = SkillInfo.Attack;
            SkillInfo rightSkill = SkillInfo.Attack;

            if (!usingSkills)
            {
                if (Input.GetMouseButton(1) || (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButton(0)))
                {
                    character.UseSkill(rightSkill, IsoInput.mousePosition);
                }
                else if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject())
                {
                    if (MouseSelection.current != null)
                    {
                        var targetCharacter = MouseSelection.current.GetComponent <Character>();
                        if (targetCharacter != null)
                        {
                            if (targetCharacter.monStat != null && targetCharacter.monStat.npc)
                            {
                                // todo interact with npc
                            }
                            else
                            {
                                character.UseSkill(leftSkill, targetCharacter);
                            }
                        }
                        else
                        {
                            character.Use(MouseSelection.current);
                        }
                    }
                    else
                    {
                        character.GoTo(IsoInput.mousePosition);
                    }
                }
                else
                {
                    character.LookAt(IsoInput.mousePosition);
                }
            }

            character.run = run;
        }