Exemple #1
0
    public T Read <T>(string key, T defaultValue = default(T))
    {
        Godot.Collections.Dictionary dict = data;
        string[] keys = key.Split(".", true);
        if (!data.Contains(key))
        {
            return(defaultValue);
        }
        var result = data[key];

        return((T)result);
    }
    private void RefreshData(int id)
    {
        Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Skill") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary skillData      = jsonDictionary["skill" + id] as Godot.Collections.Dictionary;
        GetNode <LineEdit>("NameLabel/NameText").Text = skillData["name"] as string;
        string icon = skillData["icon"] as string;

        if (icon != "")
        {
            GetNode <Sprite>("IconLabel/IconSprite").Texture = GD.Load(skillData["icon"] as string) as Godot.Texture;
        }
        GetNode <TextEdit>("DescLabel/DescText").Text = skillData["description"] as string;
        GetNode <OptionButton>("SkillTypeLabel/SkillTypeButton").Selected = Convert.ToInt32(skillData["skill_type"]);
        GetNode <SpinBox>("MPCostLabel/MPCostBox").Value            = Convert.ToInt32(skillData["mp_cost"]);
        GetNode <SpinBox>("TPCostLabel/TPCostBox").Value            = Convert.ToInt32(skillData["tp_cost"]);
        GetNode <OptionButton>("TargetLabel/TargetButton").Selected = Convert.ToInt32(skillData["target"]);
        GetNode <OptionButton>("UsableLabel/UsableButton").Selected = Convert.ToInt32(skillData["usable"]);
        GetNode <SpinBox>("HitLabel/HitBox").Value = Convert.ToInt32(skillData["success"]);
        GetNode <OptionButton>("TypeLabel/TypeButton").Selected = Convert.ToInt32(skillData["hit_type"]);
        GetNode <OptionButton>("DamageLabel/DTypeLabel/DTypeButton").Selected     = Convert.ToInt32(skillData["damage_type"]);
        GetNode <OptionButton>("DamageLabel/ElementLabel/ElementButton").Selected = Convert.ToInt32(skillData["element"]);
        GetNode <LineEdit>("DamageLabel/DFormulaLabel/FormulaText").Text          = skillData["formula"] as string;
        if (skillData.Contains("effects") == true)
        {
            this.ClearEffectList();
            Godot.Collections.Array effectList = skillData["effects"] as Godot.Collections.Array;
            foreach (Godot.Collections.Dictionary effect in effectList)
            {
                this.AddEffectList(effect["name"].ToString(), Convert.ToInt32(effect["data_id"]), effect["value1"].ToString(), effect["value2"].ToString());
            }
        }
    }
Exemple #3
0
 public static object TryGetValue(this Godot.Collections.Dictionary dict, object key)
 {
     if (dict.Contains(key))
     {
         return(dict[key]);
     }
     else
     {
         return(null);
     }
 }
Exemple #4
0
    private void Attack()
    {
        //Check if the target is still in the desired distane
        if (Position.DistanceTo(target.Position) > 300)
        {
            //Change the state to the attack state
            myState = AIStates.MoveTo;
        }
        else
        {
            //Get the direction to move in
            Vector2 dir = target.Position - Position;
            //Normalizing direction for movement
            dir = dir.Normalized();
            //gunSprite.Rotation = Mathf.LerpAngle(gunSprite.Rotation, dir.Angle(), 0.2f);
            gunSprite.LookAt(target.Position);
        }

        //If the attack timer has not run out yet we just return out of the method
        if (!canAttack)
        {
            return;
        }
        //Reset the can attack bool
        canAttack = false;
        //Start the attack timer
        attackTimer.Start();

        //so I am brute forcing the heck out of this mthod sorry
        ShowFlash();

        Physics2DDirectSpaceState worldState = GetWorld2d().DirectSpaceState;

        //Get the raycast hits and store them in a dictionary
        Godot.Collections.Dictionary hits = worldState.IntersectRay(GlobalPosition, target.GlobalPosition, new Godot.Collections.Array {
            this
        }, this.CollisionMask);
        //Check if there was a hit
        if (hits.Count > 0)
        {
            if (hits.Contains("collider"))
            {
                UnitHitEvent uhei = new UnitHitEvent();
                uhei.attacker    = (Node2D)GetParent();
                uhei.target      = (Node2D)hits["collider"];
                uhei.damage      = 5;
                uhei.Description = uhei.attacker.Name + " attacked " + uhei.target.Name;
                uhei.FireEvent();
            }
        }
    }
Exemple #5
0
    private void Fire()
    {
        /*
         * if (missileUpgrade)
         * {
         *  missile = missileScene.Instance();
         *
         *  if (((Missile)missile).HasMethod("Start"))
         *  {
         *      //((Missile)missile).Start(this.Transform, null);
         *      //((Missile)missile).Start(GetNode<Node2D>("../../../../../Main").Transform, null);
         *  }
         *  Node2D tempNode = GetNode<Node2D>("../../../../../Main/MissileContainer");
         *  tempNode.AddChild(missile);
         *  //AddChild(missile);
         *
         * }
         * else
         * {*/
        //Get a snapshot of the physics state of he world at this moment
        Physics2DDirectSpaceState worldState = GetWorld2d().DirectSpaceState;

        //Get the raycast hits and store them in a dictionary
        Godot.Collections.Dictionary hits = worldState.IntersectRay(GlobalPosition, GetGlobalMousePosition(), new Godot.Collections.Array {
            tankBody
        }, tankBody.CollisionMask);
        //Check if there was a hit
        if (hits.Count > 0)
        {
            //Change the line2d end position if there was a hit
            //hitPos = (Vector2)hits["position"];
            if (hits.Contains("collider"))
            {
                if (((Node)hits["collider"]).IsInGroup("Enemies"))
                {
                    UnitHitEvent uhei = new UnitHitEvent();
                    uhei.attacker    = (Node2D)Owner;
                    uhei.target      = (Node2D)hits["collider"];
                    uhei.damage      = 50;
                    uhei.Description = uhei.attacker.Name + " attacked " + uhei.target.Name;
                    uhei.FireEvent();
                }
            }
        }
        //Set the start and end of the line2D and then make it visible
        //traceLine.Points = new Vector2[] {Vector2.Zero, hitPos };
        //traceLine.Visible = true;
        //traceTimer.Start();
        //}
    }
    private void RefreshData(int id)
    {
        Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Weapon") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary weaponData     = jsonDictionary["weapon" + id] as Godot.Collections.Dictionary;

        jsonDictionary = this.GetParent().GetParent().Call("ReadData", "System") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary systemData = jsonDictionary["stats"] as Godot.Collections.Dictionary;

        GetNode <LineEdit>("NameLabel/NameText").Text = weaponData["name"] as string;
        string icon = weaponData["icon"] as string;

        if (icon != "")
        {
            GetNode <Sprite>("IconLabel/IconSprite").Texture = GD.Load(weaponData["icon"] as string) as Godot.Texture;
        }
        GetNode <TextEdit>("DescLabel/DescText").Text                 = weaponData["description"] as string;
        GetNode <OptionButton>("WTypeLabel/WTypeButton").Selected     = Convert.ToInt32(weaponData["weapon_type"]);
        GetNode <OptionButton>("SlotLabel/SlotButton").Selected       = Convert.ToInt32(weaponData["slot_type"]);
        GetNode <SpinBox>("PriceLabel/PriceSpin").Value               = Convert.ToInt32(weaponData["price"]);
        GetNode <OptionButton>("ElementLabel/ElementButton").Selected = Convert.ToInt32(weaponData["element"]);

        GetNode <ItemList>("StatsLabel/StatsContainer/DataContainer/StatNameCont/StatNameList").Clear();
        GetNode <ItemList>("StatsLabel/StatsContainer/DataContainer/StatValueCont/StatValueList").Clear();
        for (int i = 0; i < systemData.Count; i++)
        {
            string statName = systemData[i.ToString()] as string;
            Godot.Collections.Dictionary weaponStatFormula = weaponData["stat_list"] as Godot.Collections.Dictionary;
            string statFormula = "";
            if (weaponStatFormula.Contains(statName))
            {
                statFormula = weaponStatFormula[statName as string] as string;
            }
            else
            {
                statFormula = "0";
            }
            GetNode <ItemList>("StatsLabel/StatsContainer/DataContainer/StatNameCont/StatNameList").AddItem(statName);
            GetNode <ItemList>("StatsLabel/StatsContainer/DataContainer/StatValueCont/StatValueList").AddItem(statFormula);
        }
        if (weaponData.Contains("effects") == true)
        {
            this.ClearEffectList();
            Godot.Collections.Array effectList = weaponData["effects"] as Godot.Collections.Array;
            foreach (Godot.Collections.Dictionary effect in effectList)
            {
                this.AddEffectList(effect["name"].ToString(), Convert.ToInt32(effect["data_id"]), effect["value1"].ToString(), effect["value2"].ToString());
            }
        }
    }
    // Works backward, looking up ideal steps in cameFrom, to reproduce the full path
    public Godot.Collections.Array reconstructPath(Vector2 currentVector)
    {
        String currentVectorId = vector2ToId(currentVector);

        Godot.Collections.Array totalPath = new Godot.Collections.Array();
        totalPath.Insert(0, currentVector);

        while (cameFrom.Contains(currentVectorId))
        {
            currentVector   = (Vector2)cameFrom[currentVectorId];
            currentVectorId = vector2ToId(currentVector);
            totalPath.Insert(0, currentVector);
        }

        return(totalPath);
    }
    public static string ParseIcon(string name)
    {
        LoadCatalog();

        // If name is not known, return empty string
        if (!_catalog.Contains(name))
        {
            return("");
        }

        var keyData    = (Dictionary)_catalog[name];
        var unicodeStr = (string)keyData["unicode"];
        var unicodeInt = int.Parse(unicodeStr, System.Globalization.NumberStyles.HexNumber);

        return(char.ConvertFromUtf32(unicodeInt));
    }
    // Finds the (serialized) point in the openSet with the smallest fScore
    public String findSmallestFScore()
    {
        float  smallestFScore = Int64.MaxValue;
        String smallestPoint  = null;

        foreach (Vector2 vector in openSet.Values)
        {
            String vectorId = vector2ToId(vector);
            if (fScore.Contains(vectorId) && (float)fScore[vectorId] < smallestFScore)
            {
                smallestFScore = (float)fScore[vectorId];
                smallestPoint  = vectorId;
            }
        }

        return("" + smallestPoint);
    }
    public void RefreshData(int id)
    {
        Godot.Collections.Dictionary jsonDictionary        = this.GetParent().GetParent().Call("ReadData", "State") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary stateData             = jsonDictionary["state" + id] as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary eraseConditions       = stateData["erase_conditions"] as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary messages              = stateData["messages"] as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary customEraseConditions = stateData["custom_erase_conditions"] as Godot.Collections.Dictionary;
        GetNode <LineEdit>("NameLabel/NameLine").Text = stateData["name"] as string;
        string icon = stateData["icon"] as string;

        if (icon != "")
        {
            iconPath = stateData["icon"].ToString();
            GetNode <Sprite>("IconLabel/Sprite").Texture = GD.Load(stateData["icon"] as string) as Godot.Texture;
        }
        GetNode <OptionButton>("RestrictionLabel/RestrictionOption").Selected = Convert.ToInt32(stateData["restriction"]);
        GetNode <SpinBox>("PriorityLabel/PriorityValue").Value    = Convert.ToInt32(stateData["priority"]);
        GetNode <SpinBox>("EraseLabel/TurnsLabel/MinTurns").Value = Convert.ToInt32(eraseConditions["turns_min"]);
        GetNode <SpinBox>("EraseLabel/TurnsLabel/MaxTurns").Value = Convert.ToInt32(eraseConditions["turns_max"]);
        GetNode <SpinBox>("EraseLabel/DamageLabel/Damage").Value  = Convert.ToInt32(eraseConditions["erase_damage"]);
        GetNode <SpinBox>("EraseLabel/SetpsLabel/SpinBox").Value  = Convert.ToInt32(eraseConditions["erase_setps"]);
        GetNode <ItemList>("MessagesLabel/PanelContainer/VBoxContainer/MessageList").Clear();
        foreach (String message in messages.Values)
        {
            GetNode <ItemList>("MessagesLabel/PanelContainer/VBoxContainer/MessageList").AddItem(message);
        }
        GetNode <ItemList>("CustomEraseLabel/PanelContainer/VBoxContainer/EraseConditions").Clear();
        foreach (String condition in customEraseConditions.Values)
        {
            GetNode <ItemList>("CustomEraseLabel/PanelContainer/VBoxContainer/EraseConditions").AddItem(condition);
        }
        if (stateData.Contains("effects") == true)
        {
            this.ClearEffectList();
            Godot.Collections.Array effectList = stateData["effects"] as Godot.Collections.Array;
            foreach (Godot.Collections.Dictionary effect in effectList)
            {
                this.AddEffectList(effect["name"].ToString(), Convert.ToInt32(effect["data_id"]), effect["value1"].ToString(), effect["value2"].ToString());
            }
        }
    }
Exemple #11
0
    private static bool HasCollisionWithCollisionMaps(Godot.Collections.Dictionary collisionMap, string collisionMapKey, out bool hasFound, bool canClose = false)
    {
        var passable = true;

        hasFound = false;

        if (collisionMap.Contains(collisionMapKey))
        {
            var collisionMapValue = (Godot.Collections.Dictionary)collisionMap[collisionMapKey];

            if (canClose == true)
            {
                if (collisionMapValue.Contains("IsClosed"))
                {
                    var isClosed = bool.Parse(collisionMapValue["IsClosed"].ToString());
                    passable = !isClosed;
                    hasFound = true;

                    GD.Print($"Can Pass: {passable} {collisionMapKey}");
                }
                else
                {
                    GD.Print($"Can Pass {true} {collisionMapKey}");

                    passable = true;
                    hasFound = true;
                }
            }
            else
            {
                passable = false;
                hasFound = true;

                GD.Print($"Can Pass: {passable} {collisionMapKey}");
            }
        }

        return(passable);
    }
Exemple #12
0
    private void lineOfSightCheck()
    {
        if (target == null)
        {
            return;
        }
        Physics2DDirectSpaceState worldState = GetWorld2d().DirectSpaceState;

        //Get the raycast hits and store them in a dictionary
        Godot.Collections.Dictionary hits = worldState.IntersectRay(this.GlobalPosition, ((KinematicBody2D)target).GlobalPosition);
        if (hits.Count > 0)
        {
            if (hits.Contains("collider"))
            {
                Node2D col = (Node2D)hits["collider"];
                if (col.IsInGroup("Player"))
                {
                    targetInLineOfSight = true;
                }
            }
        }
    }
Exemple #13
0
    public void SetBarricadeStatus(string barricadeKey, bool isClosed)
    {
        Godot.Collections.Dictionary barricade;

        if (_windows.Contains(barricadeKey))
        {
            barricade = (Godot.Collections.Dictionary)_windows[barricadeKey];
        }
        else
        {
            return;
        }

        var hasIsClosed = barricade.Contains("IsClosed");

        if (hasIsClosed)
        {
            barricade["IsClosed"] = isClosed;
        }
        else
        {
            barricade.Add("IsClosed", isClosed);
        }
    }
    public void RefreshData(int id)
    {
        Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Character") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary charaData      = jsonDictionary["chara" + id] as Godot.Collections.Dictionary;
        GetNode <OptionButton>("CharacterButton").SetItemText(id, charaData["name"].ToString());
        GetNode <LineEdit>("NameLabel/NameText").Text = charaData["name"].ToString();
        string face = charaData["faceImage"].ToString();

        if (face != "")
        {
            facePath = charaData["faceImage"].ToString();
            GetNode <Sprite>("FaceLabel/FaceSprite").Texture = GD.Load(charaData["faceImage"].ToString()) as Godot.Texture;
        }
        if (charaData.Contains("description"))
        {
            GetNode <TextEdit>("DescLabel/DescText").Text = charaData["description"].ToString();
        }
        else
        {
            GetNode <TextEdit>("DescLabel/DescText").Text = "";
        }
        GetNode <SpinBox>("InitLevelLabel/InitLevelText").Value = Convert.ToInt32(charaData["initialLevel"]);
        GetNode <SpinBox>("MaxLevelLabel/MaxLevelText").Value   = Convert.ToInt32(charaData["maxLevel"]);

        jsonDictionary = this.GetParent().GetParent().Call("ReadData", "System") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary wtypeDictionary      = jsonDictionary["weapons"] as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary atypeDictionary      = jsonDictionary["armors"] as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary equipSlotsDictionary = jsonDictionary["slots"] as Godot.Collections.Dictionary;

        Godot.Collections.Dictionary etypeDictionary = charaData["equip_types"] as Godot.Collections.Dictionary;
        GetNode <ItemList>("EquipLabel/EquipContainer/EquipContainer/EquipList").Clear();
        equipIdArray.Clear();
        string equip_name;

        foreach (string equip in etypeDictionary.Keys)
        {
            string kind    = equip[0].ToString();
            string type_id = etypeDictionary[equip].ToString();
            equipIdArray.Add(Convert.ToInt32(etypeDictionary[equip]));
            switch (kind)
            {
            case "w":
                string w_id = equip.Remove(0, 1);
                equip_name = "W: " + wtypeDictionary[type_id].ToString();
                GetNode <ItemList>("EquipLabel/EquipContainer/EquipContainer/EquipList").AddItem(equip_name);
                break;

            case "a":
                string a_id = equip.Remove(0, 1);
                equip_name = "A: " + atypeDictionary[type_id].ToString();
                GetNode <ItemList>("EquipLabel/EquipContainer/EquipContainer/EquipList").AddItem(equip_name);
                break;
            }
        }

        Godot.Collections.Dictionary weaponList = this.GetParent().GetParent().Call("ReadData", "Weapon") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary armorList  = this.GetParent().GetParent().Call("ReadData", "Armor") as Godot.Collections.Dictionary;

        GetNode <ItemList>("InitialEquipLabel/PanelContainer/TypeContainer/TypeList").Clear();
        GetNode <ItemList>("InitialEquipLabel/PanelContainer/TypeContainer/EquipList").Clear();
        Godot.Collections.Dictionary initialEquipData = charaData["initial_equip"] as Godot.Collections.Dictionary;
        initialEquipIdArray.Clear();
        foreach (string equip in equipSlotsDictionary.Keys)
        {
            GetNode <ItemList>("InitialEquipLabel/PanelContainer/TypeContainer/TypeList").AddItem(equipSlotsDictionary[equip].ToString());
            string kind    = equip[0].ToString();
            int    kind_id = Convert.ToInt32(equip.Remove(0, 1));

            switch (kind)
            {
            case "w":
                int w_id = -1;
                if (kind_id < initialEquipData.Keys.Count)
                {
                    w_id = Convert.ToInt32(initialEquipData[kind_id.ToString()]);
                }

                initialEquipIdArray.Add(w_id);
                if (w_id >= 0)
                {
                    Godot.Collections.Dictionary weaponData = weaponList["weapon" + w_id] as Godot.Collections.Dictionary;
                    GetNode <ItemList>("InitialEquipLabel/PanelContainer/TypeContainer/EquipList").AddItem(weaponData["name"].ToString());
                }
                else
                {
                    GetNode <ItemList>("InitialEquipLabel/PanelContainer/TypeContainer/EquipList").AddItem("None");
                }
                break;

            case "a":
                int a_id = -1;
                if (kind_id < initialEquipData.Keys.Count)
                {
                    a_id = Convert.ToInt32(initialEquipData[kind_id.ToString()]);
                }

                initialEquipIdArray.Add(a_id);
                if (a_id >= 0)
                {
                    Godot.Collections.Dictionary armorData = armorList["armor" + a_id] as Godot.Collections.Dictionary;
                    GetNode <ItemList>("InitialEquipLabel/PanelContainer/TypeContainer/EquipList").AddItem(armorData["name"].ToString());
                }
                else
                {
                    GetNode <ItemList>("InitialEquipLabel/PanelContainer/TypeContainer/EquipList").AddItem("None");
                }
                break;
            }
        }

        jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Class") as Godot.Collections.Dictionary;
        for (int i = 0; i < jsonDictionary.Count; i++)
        {
            Godot.Collections.Dictionary classData = jsonDictionary["class" + i] as Godot.Collections.Dictionary;
            if (i > GetNode <OptionButton>("ClassLabel/ClassText").GetItemCount())
            {
                GetNode <OptionButton>("ClassLabel/ClassText").AddItem(classData["name"].ToString());
            }
            else
            {
                GetNode <OptionButton>("ClassLabel/ClassText").SetItemText(i, classData["name"].ToString());
            }
        }

        if (charaData.Contains("effects") == true)
        {
            this.ClearEffectList();
            Godot.Collections.Array effectList = charaData["effects"] as Godot.Collections.Array;
            foreach (Godot.Collections.Dictionary effect in effectList)
            {
                this.AddEffectList(effect["name"].ToString(), Convert.ToInt32(effect["data_id"]), effect["value1"].ToString(), effect["value2"].ToString());
            }
        }
    }
Exemple #15
0
    public void RefreshData(int id)
    {
        Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Class") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary classData      = jsonDictionary["class" + id] as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary classSkillList = classData["skill_list"] as Godot.Collections.Dictionary;

        jsonDictionary = this.GetParent().GetParent().Call("ReadData", "System") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary systemStatsData = jsonDictionary["stats"] as Godot.Collections.Dictionary;

        jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Skill") as Godot.Collections.Dictionary;

        GetNode <LineEdit>("NameLabel/NameText").Text = classData["name"] as string;
        string icon = classData["icon"] as string;

        if (icon != "")
        {
            GetNode <Sprite>("IconLabel/IconSprite").Texture = GD.Load(classData["icon"] as string) as Godot.Texture;
        }
        GetNode <LineEdit>("ExpLabel/ExpText").Text = classData["experience"] as string;

        GetNode <ItemList>("StatsLabel/StatsContainer/DataContainer/StatsListContainer/StatsList").Clear();
        GetNode <ItemList>("StatsLabel/StatsContainer/DataContainer/FormulaListContainer/FormulaList").Clear();
        for (int i = 0; i < systemStatsData.Count; i++)
        {
            string statName = systemStatsData[i.ToString()] as string;
            Godot.Collections.Dictionary classStatFormula = classData["stat_list"] as Godot.Collections.Dictionary;
            string statFormula = "";
            if (classStatFormula.Contains(statName))
            {
                statFormula = classStatFormula[statName].ToString();
            }
            else
            {
                statFormula = "level * 5";
            }
            GetNode <ItemList>("StatsLabel/StatsContainer/DataContainer/StatsListContainer/StatsList").AddItem(statName);
            GetNode <ItemList>("StatsLabel/StatsContainer/DataContainer/FormulaListContainer/FormulaList").AddItem(statFormula);
        }

        GetNode <ItemList>("SkillLabel/SkillContainer/HBoxContainer/SkillListContainer/SkillList").Clear();
        GetNode <ItemList>("SkillLabel/SkillContainer/HBoxContainer/SkillLevelContainer/SkillLevelList").Clear();
        skillListArray.Clear();
        foreach (string element in classSkillList.Keys)
        {
            skillListArray.Add(element);
            Godot.Collections.Dictionary skillData = jsonDictionary["skill" + element] as Godot.Collections.Dictionary;
            string skillName = skillData["name"] as string;
            GetNode <ItemList>("SkillLabel/SkillContainer/HBoxContainer/SkillListContainer/SkillList").AddItem(skillName);
            string level = Convert.ToString(classSkillList[element as string]);
            GetNode <ItemList>("SkillLabel/SkillContainer/HBoxContainer/SkillLevelContainer/SkillLevelList").AddItem(level);
        }

        GetNode <OptionButton>("SkillLabel/AddSkill/SkillLabel/OptionButton").Clear();
        foreach (string element in jsonDictionary.Keys)
        {
            Godot.Collections.Dictionary skillData = jsonDictionary[element] as Godot.Collections.Dictionary;
            string name = Convert.ToString(skillData["name"]);
            GetNode <OptionButton>("SkillLabel/AddSkill/SkillLabel/OptionButton").AddItem(name);
            GetNode <OptionButton>("SkillLabel/AddSkill/SkillLabel/OptionButton").Select(0);
        }
        if (classData.Contains("effects") == true)
        {
            this.ClearEffectList();
            Godot.Collections.Array effectList = classData["effects"] as Godot.Collections.Array;
            foreach (Godot.Collections.Dictionary effect in effectList)
            {
                this.AddEffectList(effect["name"].ToString(), Convert.ToInt32(effect["data_id"]), effect["value1"].ToString(), effect["value2"].ToString());
            }
        }
    }
Exemple #16
0
    // Called when the node enters the scene tree for the first time.
    public void Start()
    {
        Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "System") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary statsData      = jsonDictionary["stats"] as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary weaponsData    = jsonDictionary["weapons"] as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary armorsData     = jsonDictionary["armors"] as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary elementsData   = jsonDictionary["elements"] as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary slotsData      = jsonDictionary["slots"] as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary skillsData;

        if (jsonDictionary.Contains("skills"))
        {
            skillsData = jsonDictionary["skills"] as Godot.Collections.Dictionary;
        }
        else
        {
            skillsData = new Godot.Collections.Dictionary();
            skillsData.Add("0", "Skills");
            skillsData.Add("1", "Magic");
            jsonDictionary["skills"] = skillsData;
            this.GetParent().GetParent().Call("StoreData", "System", jsonDictionary);
        }

        GetNode <ItemList>("StatsLabel/StatsContainer/StatsBoxContainer/StatsList").Clear();
        GetNode <ItemList>("WeaponTypesLabel/WeaponTypesContainer/WpBoxContainer/WeaponList").Clear();
        GetNode <ItemList>("ArmorTypesLabel/ArmorTypesContainer/ArBoxContainer/ArmorList").Clear();
        GetNode <ItemList>("ElementLabel/ElementContainer/EleBoxContainer/ElementList").Clear();
        GetNode <ItemList>("EquipmentLabel/EquipContainer/SetContainer/SetDivisor/KindList").Clear();
        GetNode <ItemList>("EquipmentLabel/EquipContainer/SetContainer/SetDivisor/TypeList").Clear();
        GetNode <ItemList>("SkillTypesLabel/SkillTypeContainer/VBoxContainer/SkillTypeList").Clear();

        for (int i = 0; i < statsData.Count; i++)
        {
            ItemList item = GetNode <ItemList>("StatsLabel/StatsContainer/StatsBoxContainer/StatsList");
            item.AddItem((statsData[i.ToString()]).ToString());
        }

        for (int i = 0; i < weaponsData.Count; i++)
        {
            ItemList item = GetNode <ItemList>("WeaponTypesLabel/WeaponTypesContainer/WpBoxContainer/WeaponList");
            item.AddItem((weaponsData[i.ToString()]).ToString());
        }

        for (int i = 0; i < armorsData.Count; i++)
        {
            ItemList item = GetNode <ItemList>("ArmorTypesLabel/ArmorTypesContainer/ArBoxContainer/ArmorList");
            item.AddItem((armorsData[i.ToString()]).ToString());
        }

        for (int i = 0; i < elementsData.Count; i++)
        {
            ItemList item = GetNode <ItemList>("ElementLabel/ElementContainer/EleBoxContainer/ElementList");
            item.AddItem((elementsData[i.ToString()]).ToString());
        }

        for (int i = 0; i < skillsData.Count; i++)
        {
            ItemList item = GetNode <ItemList>("SkillTypesLabel/SkillTypeContainer/VBoxContainer/SkillTypeList");
            item.AddItem((skillsData[i.ToString()]).ToString());
        }

        foreach (string id in slotsData.Keys)
        {
            ItemList kind   = GetNode <ItemList>("EquipmentLabel/EquipContainer/SetContainer/SetDivisor/KindList");
            String   kindId = id[0].ToString();
            ItemList type   = GetNode <ItemList>("EquipmentLabel/EquipContainer/SetContainer/SetDivisor/TypeList");
            switch (kindId)
            {
            case "w":
                kind.AddItem("Weapon");
                type.AddItem((slotsData[id]).ToString());
                break;

            case "a":
                kind.AddItem("Armor");
                type.AddItem((slotsData[id]).ToString());
                break;
            }
        }
    }
    // Entrypoint to the pathfinding algorithm. Will return either null or an array of Vector2s
    public Godot.Collections.Array path(Vector2 start, Vector2 end, World2D space_state, Godot.Collections.Array exclude_bodies, GameWorld gameWorld)
    {
        this.gameWorld = gameWorld;

        int iteration = 0;

        // Update class variables
        space    = space_state;
        excludes = exclude_bodies;

        start = normalizePoint(start);
        end   = normalizePoint(end);
        String startId = vector2ToId(start);
        String endId   = vector2ToId(end);

        cameFrom = new Godot.Collections.Dictionary();
        openSet  = new Godot.Collections.Dictionary();
        openSet.Add(startId, start);
        gScore = new Godot.Collections.Dictionary();
        fScore = new Godot.Collections.Dictionary();

        gScore.Add(startId, 0.0f);
        fScore.Add(startId, hDistance(end, start));

        // As long as we have points to visit, let's visit them
        // But not more than max_iterations times.

        while (openSet.Count > 0 && iteration < max_iterations)
        {
            // We're going to grab the current best tile, then look at its neighbors
            String currentId = findSmallestFScore();

            Vector2 current = (Vector2)openSet[currentId];

            // We reached the goal, so stop here and return the path.
            if (currentId == endId)
            {
                return(reconstructPath(current));
            }

            openSet.Remove(currentId);

            Godot.Collections.Array neighbors = getNeighbors(current);

            foreach (Vector2 neighbor in neighbors)
            {
                String neighborId     = vector2ToId(neighbor);
                float  neighborGScore = Int32.MaxValue;

                // We've seen this neighbor before, likely when passing through from a different path.
                if (gScore.Contains(neighborId))
                {
                    neighborGScore = (float)gScore[neighborId];
                }

                // This is the "new" gScore as taken through _this_ path, not the previous path
                float tentativeGscore = ((float)(gScore[currentId])) + GRID_SIZE;


                // If this path is better than the previous path through this neighbor, record it
                if (tentativeGscore < neighborGScore)
                {
                    // This lets us work backwards through best-points later
                    if (!cameFrom.Contains(neighborId))
                    {
                        cameFrom.Add(neighborId, current);
                    }

                    // gScore is the actual distance it took to get here from the start
                    if (!gScore.Contains(neighborId))
                    {
                        gScore.Add(neighborId, tentativeGscore);
                    }

                    // fScore is the actual distance from the start plus the estimated distance to the end
                    // Whoever has the best fScore in the openSet gets our attention next
                    // Therefore we are always inspecting the current best-guess-path
                    if (!fScore.Contains(neighborId))
                    {
                        fScore.Add(neighborId, tentativeGscore + hDistance(end, neighbor));
                    }

                    // This would allow revisiting if the heuristic were not consistent
                    // But in our use case we should not end up revisiting nodes
                    if (!openSet.Contains(neighborId))
                    {
                        openSet.Add(neighborId, neighbor);
                    }
                }
            }

            iteration++;
        }

        // No path found
        return(null);
    }
Exemple #18
0
    public void RefreshData(int id)
    {
        Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Enemy") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary enemyData      = jsonDictionary["enemy" + id] as Godot.Collections.Dictionary;

        jsonDictionary = this.GetParent().GetParent().Call("ReadData", "System") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary systemStatsData = jsonDictionary["stats"] as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary itemList        = this.GetParent().GetParent().Call("ReadData", "Item") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary weaponList      = this.GetParent().GetParent().Call("ReadData", "Weapon") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary armorList       = this.GetParent().GetParent().Call("ReadData", "Armor") as Godot.Collections.Dictionary;

        GetNode <LineEdit>("NameLabel/NameLine").Text = enemyData["name"] as string;
        string graphic = enemyData["graphicImage"] as string;

        if (graphic != "")
        {
            graphicsPath = enemyData["graphicImage"] as string;
            GetNode <Sprite>("GraphicLabel/Graphic").Texture = GD.Load(enemyData["graphicImage"] as string) as Godot.Texture;
        }

        GetNode <ItemList>("StatsLabel/StatsContainer/DataContainer/StatList").Clear();
        GetNode <ItemList>("StatsLabel/StatsContainer/DataContainer/FormulaList").Clear();
        for (int i = 0; i < systemStatsData.Count; i++)
        {
            string statName = systemStatsData[i.ToString()] as string;
            Godot.Collections.Dictionary enemyStatFormula = enemyData["stat_list"] as Godot.Collections.Dictionary;
            string statFormula = "";
            if (enemyStatFormula.Contains(statName))
            {
                statFormula = enemyStatFormula[statName].ToString();
            }
            else
            {
                statFormula = "level * 5";
            }
            GetNode <ItemList>("StatsLabel/StatsContainer/DataContainer/StatList").AddItem(statName);
            GetNode <ItemList>("StatsLabel/StatsContainer/DataContainer/FormulaList").AddItem(statFormula);
        }

        Godot.Collections.Dictionary dropList = enemyData["drop_list"] as Godot.Collections.Dictionary;

        GetNode <ItemList>("DropsLabel/DropsContainer/VBoxContainer/HBoxContainer/DropsList").Clear();
        GetNode <ItemList>("DropsLabel/DropsContainer/VBoxContainer/HBoxContainer/ChanceList").Clear();
        dropIdArray.Clear();
        foreach (string drop in dropList.Keys)
        {
            string kind    = drop[0].ToString();
            string kind_id = drop.Remove(0, 1);
            switch (kind)
            {
            case "i":
                dropIdArray.Add(drop);
                Godot.Collections.Dictionary itemData = itemList["item" + kind_id] as Godot.Collections.Dictionary;
                GetNode <ItemList>("DropsLabel/DropsContainer/VBoxContainer/HBoxContainer/DropsList").AddItem(itemData["name"].ToString());
                break;

            case "w":
                dropIdArray.Add(drop);
                Godot.Collections.Dictionary weaponData = weaponList["weapon" + kind_id] as Godot.Collections.Dictionary;
                GetNode <ItemList>("DropsLabel/DropsContainer/VBoxContainer/HBoxContainer/DropsList").AddItem(weaponData["name"].ToString());
                break;

            case "a":
                dropIdArray.Add(drop);
                Godot.Collections.Dictionary armorData = armorList["armor" + kind_id] as Godot.Collections.Dictionary;
                GetNode <ItemList>("DropsLabel/DropsContainer/VBoxContainer/HBoxContainer/DropsList").AddItem(armorData["name"].ToString());
                break;
            }
            GetNode <ItemList>("DropsLabel/DropsContainer/VBoxContainer/HBoxContainer/ChanceList").AddItem(dropList[drop].ToString());
        }
        GetNode <SpinBox>("ExpLabel/ExpSpin").Value   = Convert.ToInt32(enemyData["experience"]);
        GetNode <SpinBox>("GoldLabel/GoldSpin").Value = Convert.ToInt32(enemyData["money"]);

        if (enemyData.Contains("effects") == true)
        {
            this.ClearEffectList();
            Godot.Collections.Array effectList = enemyData["effects"] as Godot.Collections.Array;
            foreach (Godot.Collections.Dictionary effect in effectList)
            {
                this.AddEffectList(effect["name"].ToString(), Convert.ToInt32(effect["data_id"]), effect["value1"].ToString(), effect["value2"].ToString());
            }
        }
    }
    private void _on_EquipList_item_activated(int index)
    {
        initialEquipEdit = index;
        equipEditArray.Add("-1");
        GetNode <Label>("InitialEquipLabel/InitialEquipChange/Label").Text = GetNode <ItemList>("InitialEquipLabel/PanelContainer/TypeContainer/TypeList").GetItemText(index);

        GetNode <OptionButton>("InitialEquipLabel/InitialEquipChange/Label/OptionButton").Clear();
        GetNode <OptionButton>("InitialEquipLabel/InitialEquipChange/Label/OptionButton").AddItem("None");
        Godot.Collections.Dictionary jsonDictionary = this.GetParent().GetParent().Call("ReadData", "Character") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary charaData      = jsonDictionary["chara" + characterSelected] as Godot.Collections.Dictionary;

        jsonDictionary = this.GetParent().GetParent().Call("ReadData", "System") as Godot.Collections.Dictionary;
        Godot.Collections.Dictionary slotsData = jsonDictionary["slots"] as Godot.Collections.Dictionary;

        Godot.Collections.Dictionary equipTypesData = charaData["equip_types"] as Godot.Collections.Dictionary;
        if (slotsData.Contains("w" + index))
        {
            Godot.Collections.Dictionary weaponList = this.GetParent().GetParent().Call("ReadData", "Weapon") as Godot.Collections.Dictionary;

            Godot.Collections.Array <int> weaponArray = new Godot.Collections.Array <int>();
            foreach (string key in equipTypesData.Keys)
            {
                string kind = key[0].ToString();
                if (kind == "w")
                {
                    weaponArray.Add(Convert.ToInt32(equipTypesData[key]));
                }
            }

            foreach (string weapon in weaponList.Keys)
            {
                Godot.Collections.Dictionary weaponData = weaponList[weapon] as Godot.Collections.Dictionary;
                if (weaponArray.Contains(Convert.ToInt32(weaponData["weapon_type"])))
                {
                    equipEditArray.Add(weapon.Remove(0, 6));
                    GetNode <OptionButton>("InitialEquipLabel/InitialEquipChange/Label/OptionButton").AddItem(weaponData["name"].ToString());
                }
            }
        }
        else if (slotsData.Contains("a" + index))
        {
            Godot.Collections.Dictionary armorList = this.GetParent().GetParent().Call("ReadData", "Armor") as Godot.Collections.Dictionary;

            Godot.Collections.Array <int> armorArray = new Godot.Collections.Array <int>();
            foreach (string key in equipTypesData.Keys)
            {
                string kind = key[0].ToString();
                if (kind == "a")
                {
                    armorArray.Add(Convert.ToInt32(equipTypesData[key]));
                }
            }

            foreach (string armor in armorList.Keys)
            {
                Godot.Collections.Dictionary armorData = armorList[armor] as Godot.Collections.Dictionary;
                if (armorArray.Contains(Convert.ToInt32(armorData["armor_type"])))
                {
                    equipEditArray.Add(armor.Remove(0, 5));
                    GetNode <OptionButton>("InitialEquipLabel/InitialEquipChange/Label/OptionButton").AddItem(armorData["name"].ToString());
                }
            }
        }
        GetNode <WindowDialog>("InitialEquipLabel/InitialEquipChange").PopupCentered();
    }
Exemple #20
0
    private void buildObstacles()
    {
        Rect2 usedRect = _tileMap.GetUsedRect();

        int startPointX = (int)usedRect.Position.x;
        int startPointY = (int)usedRect.Position.y;

        int maxLengthX = (int)usedRect.Size.x;
        int maxLengthY = (int)usedRect.Size.y;

        Godot.Collections.Dictionary prebuildObstacles = new Godot.Collections.Dictionary();

        if (GetTree().NetworkPeer == null || GetTree().IsNetworkServer())
        {
            // Add pre - added obstacles
            foreach (Node2D obstacle in GetChildren())
            {
                Vector2 pos = _tileMap.WorldToMap(obstacle.Position);
                prebuildObstacles.Add(pos.x + _obstacleIndexSeparator + pos.y, pos);

                float x = pos.x;
                float y = pos.y;
                prebuildObstacles.Add(x + _obstacleIndexSeparator + y, new Vector2(x, y));
            }
        }

        for (int xIndex = startPointX; xIndex < maxLengthX; xIndex++)
        {
            for (int yIndex = startPointY; yIndex < maxLengthY; yIndex++)
            {
                // if there is already obstacle on it, then ignore this tile, this is also not workable tile, so skip entire logic to next tile
                if (prebuildObstacles.Contains(xIndex + _obstacleIndexSeparator + yIndex))
                {
                    continue;
                }

                Vector2        position;
                Obstacle.Items item = Obstacle.Items.remain;

                if (_tileMap.GetCell(xIndex, yIndex) == 0)
                {
                    item = Obstacle.Items.crate_wood;
                }
                else if (_tileMap.GetCell(xIndex, yIndex) == 45 || _tileMap.GetCell(xIndex, yIndex) == 46)
                {
                    item = Obstacle.Items.crate_steel;
                }
                else if (_tileMap.GetCell(xIndex, yIndex) == 7)
                {
                    item = Obstacle.Items.roadblock_red;
                }

                Label mapLabel = (Label)GetNode("../MapCoordinate").Duplicate();
                mapLabel.Text = ("(" + xIndex + "," + yIndex + ")");
                mapLabel.Name = "maplabel_" + xIndex + _obstacleIndexSeparator + yIndex;

                position = _tileMap.MapToWorld(new Vector2(xIndex, yIndex));

                if (item != Obstacle.Items.remain)
                {
                    Obstacle obstacle = (Obstacle)((PackedScene)GD.Load("res://environments/Obstacle.tscn")).Instance();
                    obstacle.type = item;

                    obstacle.Name = _obstaclePrefix + xIndex + _obstacleIndexSeparator + yIndex;

                    AddChild(obstacle);

                    obstacle.GlobalPosition = position + _halfCellSize;

                    mapLabel.Set("custom_colors/font_color", new Color("#ff0000"));
                }
                else
                {
                    if (GetTree().NetworkPeer == null || GetTree().IsNetworkServer())
                    {
                        // As there is no obstacle, this cell is a workable path
                        _traverableTiles.Add(new Vector2(xIndex, yIndex));
                    }

                    mapLabel.Set("custom_colors/font_color", new Color("#0016ff"));
                }

                mapLabel.SetGlobalPosition(position + _halfCellSize);

                AddChild(mapLabel);
            }
        }

        if (GetTree().NetworkPeer == null || GetTree().IsNetworkServer())
        {
            _buildObstaclesCache();
        }
    }