Ejemplo n.º 1
0
        public static GuardianCommonStatus LoadStatus(int CompanionID, string CompanionModID = "")
        {
            if (CompanionModID == "")
            {
                CompanionModID = MainMod.mod.Name;
            }
            GuardianBase Base          = GuardianBase.GetGuardianBase(CompanionID, CompanionModID);
            string       SaveDirectory = GetSaveFolder + "/" + CompanionModID;

            if (!Directory.Exists(SaveDirectory))
            {
                return(new GuardianCommonStatus());
            }
            string SaveFile = SaveDirectory + "/" + Base.Name + ".tgf";

            if (!File.Exists(SaveFile))
            {
                return(new GuardianCommonStatus());
            }
            GuardianCommonStatus status = new GuardianCommonStatus();

            using (FileStream stream = new FileStream(SaveFile, FileMode.Open))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    int ModVersion = reader.ReadInt32();
                    status.LifeCrystalsUsed = reader.ReadByte();
                    status.LifeFruitsUsed   = reader.ReadByte();
                    status.ManaCrystalsUsed = reader.ReadByte();
                    if (ModVersion >= 94)
                    {
                        if (reader.ReadBoolean())
                        {
                            status.LifeTime = TimeSpan.FromSeconds(reader.ReadDouble());
                        }
                    }
                    int Skills = reader.ReadInt32();
                    for (int s = 0; s < Skills; s++)
                    {
                        string SkillName     = reader.ReadString();
                        int    SkillLevel    = reader.ReadInt32();
                        float  SkillProgress = reader.ReadSingle();
                        foreach (GuardianSkills sk in status.SkillList)
                        {
                            if (sk.skillType.ToString() == SkillName)
                            {
                                sk.Level    = SkillLevel;
                                sk.Progress = SkillProgress;
                                break;
                            }
                        }
                    }
                    status.LastTotalSkillLevel = reader.ReadInt32();
                }
            }
            return(status);
        }
Ejemplo n.º 2
0
        public static void SaveStatus(int CompanionID, string CompanionModID = "")
        {
            if (CompanionModID == "")
            {
                CompanionModID = MainMod.mod.Name;
            }
            GuardianBase Base          = GuardianBase.GetGuardianBase(CompanionID, CompanionModID);
            string       SaveDirectory = GetSaveFolder + "/" + CompanionModID;

            if (!Directory.Exists(SaveDirectory))
            {
                Directory.CreateDirectory(SaveDirectory);
            }
            string SaveFile = SaveDirectory + "/" + Base.Name + ".tgf";

            if (File.Exists(SaveFile))
            {
                File.Delete(SaveFile);
            }
            GuardianCommonStatus status = GetCommonStatus(CompanionID, CompanionModID);

            using (FileStream stream = new FileStream(SaveFile, FileMode.CreateNew))
            {
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    writer.Write(MainMod.ModVersion);
                    writer.Write(status.LifeCrystalsUsed);
                    writer.Write(status.LifeFruitsUsed);
                    writer.Write(status.ManaCrystalsUsed);
                    if (status.LifeTime.HasValue)
                    {
                        writer.Write(true);
                        writer.Write(status.LifeTime.Value.TotalSeconds);
                    }
                    else
                    {
                        writer.Write(false);
                    }
                    int Skills = status.SkillList.Count;
                    writer.Write(Skills);
                    for (int s = 0; s < Skills; s++)
                    {
                        GuardianSkills skill = status.SkillList[s];
                        writer.Write(skill.skillType.ToString());
                        writer.Write(skill.Level);
                        writer.Write(skill.Progress);
                    }
                    writer.Write(status.LastTotalSkillLevel);
                }
            }
        }
Ejemplo n.º 3
0
        public void Load(Terraria.ModLoader.IO.TagCompound tag, int ModVersion, int UniqueID)
        {
            ID = tag.GetInt("GuardianID_" + UniqueID);
            if (ModVersion >= 35)
            {
                ModID = tag.GetString("GuardianModID_" + UniqueID);
            }
            else
            {
                ModID = MainMod.mod.Name;
            }
            if (ModVersion >= 19 && tag.ContainsKey("Name_" + UniqueID))
            {
                _Name = tag.GetString("Name_" + UniqueID);
                if (_Name == "")
                {
                    _Name = null;
                }
            }
            if (ModVersion >= 72)
            {
                PickedName = tag.GetByte("NameID_" + UniqueID);
                GuardianBase gb = Base;
                if (gb.PossibleNames.Length > 0 && PickedName > gb.PossibleNames.Length)
                {
                    PickedName = (byte)Main.rand.Next(gb.PossibleNames.Length);
                }
            }
            if (ModVersion >= 52)
            {
                IsStarter = tag.GetBool("StarterFlag_" + UniqueID);
            }
            if (ModVersion >= 7)
            {
                FriendshipLevel       = tag.GetByte("FriendshipLevel_" + UniqueID);
                FriendshipProgression = tag.GetByte("FriendshipProgress_" + UniqueID);
                TravellingStacker     = tag.GetFloat("TravellingStacker_" + UniqueID);
            }
            if (ModVersion >= 18)
            {
                DamageStacker = tag.GetFloat("DamageStacker_" + UniqueID);
            }
            if (ModVersion >= 25)
            {
                FoodStacker  = tag.GetByte("FoodStacker_" + UniqueID);
                DrinkStacker = tag.GetByte("DrinkStacker_" + UniqueID);
            }
            if (ModVersion >= 64)
            {
                ComfortStack  = tag.GetFloat("ComfortStack_" + UniqueID);
                ComfortPoints = tag.GetByte("ComfortPoints_" + UniqueID);
            }
            float HealthPercentage = -1;

            if (ModVersion >= 1)
            {
                HealthPercentage = tag.GetFloat("HealthPercentage_" + UniqueID);
                if (HealthPercentage >= 0)
                {
                    if (HealthPercentage <= 0)
                    {
                        HP = 1;
                    }
                    else
                    {
                        HP = (int)(MHP * HealthPercentage);
                    }
                }
            }
            if (ModVersion >= 58)
            {
                KnockedOut     = tag.GetBool("IsKnockedOut_" + UniqueID);
                KnockedOutCold = tag.GetBool("IsKnockedOutCold_" + UniqueID);
            }
            LifeCrystalHealth = (ModVersion < 42 ? (byte)tag.GetInt("LifeCrystals_" + UniqueID) : tag.GetByte("LifeCrystals_" + UniqueID));
            LifeFruitHealth   = (ModVersion < 42 ? (byte)tag.GetInt("LifeFruits_" + UniqueID) : tag.GetByte("LifeFruits_" + UniqueID));
            if (ModVersion >= 33)
            {
                Male = tag.GetBool("IsMale_" + UniqueID);
            }
            if (ModVersion >= 32 && ModVersion < 42)
            {
                tag.GetBool("ExtraAccessorySlot_" + UniqueID);
            }
            if (ModVersion >= 27)
            {
                ManaCrystals = (ModVersion < 42 ? (byte)tag.GetInt("ManaCrystals_" + UniqueID) : tag.GetByte("ManaCrystals_" + UniqueID));
            }
            if (ModVersion >= 5)
            {
                tactic = (CombatTactic)tag.GetByte("CombatTactic_" + UniqueID);
            }
            if (ModVersion >= 6)
            {
                Tanker = tag.GetBool("TankingFlag_" + UniqueID);
            }
            if (ModVersion >= 11)
            {
                OverrideQuickMountToMountGuardianInstead = tag.GetBool("QuickMountOverride_" + UniqueID);
            }
            if (ModVersion >= 12)
            {
                UseHeavyMeleeAttackWhenMounted = tag.GetBool("MountMeleeUsageToggle_" + UniqueID);
            }
            if (ModVersion >= 13)
            {
                AvoidCombat = tag.GetBool("AvoidCombat_" + UniqueID);
                ChargeAhead = tag.GetBool("ChargeAhead_" + UniqueID);
            }
            if (ModVersion >= 17)
            {
                Passive        = tag.GetBool("Passive_" + UniqueID);
                AttackMyTarget = tag.GetBool("AttackMyTarget_" + UniqueID);
            }
            if (ModVersion >= 21)
            {
                SitOnTheMount = tag.GetBool("SitOnMount_" + UniqueID);
            }
            if (ModVersion >= 26)
            {
                MayLootItems = tag.GetBool("MayLootItems_" + UniqueID);
            }
            if (ModVersion >= 28)
            {
                SetToPlayerSize = tag.GetBool("SetToPlayerSize_" + UniqueID);
            }
            if (ModVersion >= 31)
            {
                GetItemsISendtoTrash = tag.GetBool("GetItemsISendtoTrash_" + UniqueID);
            }
            if (ModVersion >= 41)
            {
                UseWeaponsByInventoryOrder = tag.GetBool("UseWeaponsByInventoryOrder" + UniqueID);
            }
            if (ModVersion >= 46)
            {
                ProtectMode = tag.GetBool("ProtectMode" + UniqueID);
            }
            if (ModVersion >= 49)
            {
                AutoSellWhenInvIsFull = tag.GetBool("AutoSell" + UniqueID);
            }
            if (ModVersion >= 65)
            {
                HideWereForm = tag.GetBool("HideWereForm" + UniqueID);
            }
            if (ModVersion >= 30)
            {
                GiftGiven = tag.GetBool("GiftGiven_" + UniqueID);
            }
            if (ModVersion >= 53)
            {
                for (int i = 0; i < 8; i++)
                {
                    MessageTriggerFlags[i] = tag.GetBool("MessageFlags" + i + "_" + UniqueID);
                    if (ModVersion < 78)
                    {
                        tag.GetBool("FriendLevelFlags" + i + "_" + UniqueID);
                    }
                }
            }
            int ContainerSize = tag.GetInt("InventorySize_" + UniqueID);

            for (int i = 0; i < ContainerSize; i++)
            {
                Item j = new Item();
                if (ModVersion < 2)
                {
                    j.SetDefaults(tag.GetInt("Inventory_" + i + "_Type_" + UniqueID), true);
                    j.stack  = tag.GetInt("Inventory_" + i + "_Stack_" + UniqueID);
                    j.prefix = tag.GetByte("Inventory_" + i + "_Prefix_" + UniqueID);
                }
                else
                {
                    bool ItemExists = true;
                    if (ModVersion >= 3)
                    {
                        ItemExists = tag.GetBool("Inventory_" + i + "_exists_" + UniqueID);
                    }
                    if (ItemExists)
                    {
                        j = tag.Get <Item>("Inventory_" + i + "_" + UniqueID);
                    }
                }
                if (i < Inventory.Length)
                {
                    Inventory[i] = j;
                }
            }
            ContainerSize = tag.GetInt("EquipmentsSize_" + UniqueID);
            for (int e = 0; e < ContainerSize; e++)
            {
                Item j = new Item();
                if (ModVersion < 4)
                {
                    j.SetDefaults(tag.GetInt("Equipment_" + e + "_Type_" + UniqueID), true);
                    j.stack  = tag.GetInt("Equipment_" + e + "_Stack_" + UniqueID);
                    j.prefix = tag.GetByte("Equipment_" + e + "_Prefix_" + UniqueID);
                }
                else
                {
                    if (tag.GetBool("Equipment_" + e + "_exists_" + UniqueID))
                    {
                        j = tag.Get <Item>("Equipment_" + e + "_" + UniqueID);
                    }
                }
                if (e < Equipments.Length)
                {
                    Equipments[e] = j;
                }
            }
            if (ModVersion >= 22)
            {
                int BuffCount = tag.GetInt("BuffCount_" + UniqueID);
                for (int b = 0; b < BuffCount; b++)
                {
                    int ID   = tag.GetInt("Buff_" + b + "_type_" + UniqueID),
                        Time = tag.GetInt("Buff_" + b + "_time_" + UniqueID);
                    if (Time > 0)
                    {
                        Buffs.Add(new BuffData(ID, Time));
                    }
                }
            }
            if (ModVersion >= 23)
            {
                int      SkillCount = tag.GetInt("SkillCount_" + UniqueID);
                string[] SkillNames = Enum.GetNames(typeof(GuardianSkills.SkillTypes));
                for (int s = 0; s < SkillCount; s++)
                {
                    string SkillType     = tag.GetString("SkillType_" + s + "_" + UniqueID);
                    int    SkillLevel    = tag.GetInt("SkillLevel_" + s + "_" + UniqueID);
                    float  SkillProgress = tag.GetFloat("SkillProgress_" + s + "_" + UniqueID);
                    for (int s2 = 0; s2 < SkillNames.Length; s2++)
                    {
                        if (SkillNames[s2] == SkillType)
                        {
                            SkillList[s2].Level    = SkillLevel;
                            SkillList[s2].Progress = SkillProgress;
                            break;
                        }
                    }
                }
            }
            if (ModVersion >= 29)
            {
                BodyDye.SetDefaults(tag.GetInt("BodyDye_" + UniqueID), true);
            }
            if (ModVersion >= 56)
            {
                Fatigue = (sbyte)tag.GetByte("FatigueCount_" + UniqueID);
                Injury  = (sbyte)tag.GetByte("InjuryCount_" + UniqueID);
            }

            /*if (ModVersion >= 61)
             * {
             *  request.Load(tag, ModVersion, UniqueID, this);
             * }*/
            if (ModVersion >= 101)
            {
                request.Load(tag, "Request_" + UniqueID, ModVersion);
            }
            //if (ModVersion >= 8)
            //    request.Load(tag, ModVersion, UniqueID);

            /*if (ModVersion < 95)
             * {
             *  if (ModVersion <= 80)
             *  {
             *      if (ModVersion >= 15)
             *          LifeTime = TimeSpan.FromSeconds(tag.GetDouble("ExistenceTime_" + UniqueID));
             *  }
             *  else
             *  {
             *      if (tag.GetBool("HasExistenceTime_" + UniqueID))
             *      {
             *          LifeTime = TimeSpan.FromSeconds(tag.GetDouble("ExistenceTime_" + UniqueID));
             *      }
             *  }
             * }*/
            if (ModVersion >= 66)
            {
                SkinID   = tag.GetByte("SkinID_" + UniqueID);
                OutfitID = tag.GetByte("OutfitID_" + UniqueID);
            }
            if (ModVersion >= 67)
            {
                _Coins = (uint)(tag.GetInt("Coins_" + UniqueID) + int.MaxValue);
            }
            if (ModVersion < 80)
            {
                ResetSkillsProgress();
            }
            if (ModVersion >= 83)
            {
                LoadCustom(tag, ModVersion, UniqueID);
            }
            if (ModVersion < 90)
            {
                GuardianCommonStatus status = GetCommonStatus;
                if (status.LifeCrystalsUsed < LifeCrystalHealth)
                {
                    status.LifeCrystalsUsed = LifeCrystalHealth;
                }
                if (status.LifeFruitsUsed < LifeFruitHealth)
                {
                    status.LifeFruitsUsed = LifeFruitHealth;
                }
                if (status.ManaCrystalsUsed < ManaCrystals)
                {
                    status.ManaCrystalsUsed = ManaCrystals;
                }
                foreach (GuardianSkills skill in status.SkillList)
                {
                    foreach (GuardianSkills other in SkillList)
                    {
                        if (skill.skillType == other.skillType && skill.Level < other.Level)
                        {
                            skill.Level    = other.Level;
                            skill.Progress = other.Progress;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void Save(Terraria.ModLoader.IO.TagCompound tag, int UniqueID)
        {
            tag.Add("GuardianID_" + UniqueID, ID);
            tag.Add("GuardianModID_" + UniqueID, ModID);
            if (_Name != null)
            {
                tag.Add("Name_" + UniqueID, _Name);
            }
            tag.Add("NameID_" + UniqueID, PickedName);
            tag.Add("StarterFlag_" + UniqueID, IsStarter);
            tag.Add("FriendshipLevel_" + UniqueID, FriendshipLevel);
            tag.Add("FriendshipProgress_" + UniqueID, FriendshipProgression);
            tag.Add("TravellingStacker_" + UniqueID, TravellingStacker);
            tag.Add("DamageStacker_" + UniqueID, DamageStacker);
            tag.Add("FoodStacker_" + UniqueID, FoodStacker);
            tag.Add("DrinkStacker_" + UniqueID, DrinkStacker);
            tag.Add("ComfortStack_" + UniqueID, ComfortStack);
            tag.Add("ComfortPoints_" + UniqueID, ComfortPoints);
            tag.Add("HealthPercentage_" + UniqueID, HP <= 0 ? 0 : (HP == MHP ? 1f : (float)HP / MHP));
            tag.Add("IsKnockedOut_" + UniqueID, KnockedOut);
            tag.Add("IsKnockedOutCold_" + UniqueID, KnockedOutCold);
            tag.Add("LifeCrystals_" + UniqueID, LifeCrystalHealth);
            tag.Add("LifeFruits_" + UniqueID, LifeFruitHealth);
            tag.Add("IsMale_" + UniqueID, Male);
            tag.Add("ManaCrystals_" + UniqueID, ManaCrystals);
            tag.Add("CombatTactic_" + UniqueID, (byte)tactic);
            tag.Add("TankingFlag_" + UniqueID, Tanker);
            tag.Add("QuickMountOverride_" + UniqueID, OverrideQuickMountToMountGuardianInstead);
            tag.Add("MountMeleeUsageToggle_" + UniqueID, UseHeavyMeleeAttackWhenMounted);
            tag.Add("AvoidCombat_" + UniqueID, AvoidCombat);
            tag.Add("ChargeAhead_" + UniqueID, ChargeAhead);
            tag.Add("Passive_" + UniqueID, Passive);
            tag.Add("AttackMyTarget_" + UniqueID, AttackMyTarget);
            tag.Add("SitOnMount_" + UniqueID, SitOnTheMount);
            tag.Add("MayLootItems_" + UniqueID, MayLootItems);
            tag.Add("SetToPlayerSize_" + UniqueID, SetToPlayerSize);
            tag.Add("GetItemsISendtoTrash_" + UniqueID, GetItemsISendtoTrash);
            tag.Add("UseWeaponsByInventoryOrder" + UniqueID, UseWeaponsByInventoryOrder);
            tag.Add("ProtectMode" + UniqueID, ProtectMode);
            tag.Add("AutoSell" + UniqueID, AutoSellWhenInvIsFull);
            tag.Add("HideWereForm" + UniqueID, HideWereForm);
            tag.Add("GiftGiven_" + UniqueID, GiftGiven);
            for (int i = 0; i < 8; i++)
            {
                tag.Add("MessageFlags" + i + "_" + UniqueID, MessageTriggerFlags[i]); //It crashes
            }
            int InventorySize = Inventory.Length;

            tag.Add("InventorySize_" + UniqueID, InventorySize);
            for (int i = 0; i < InventorySize; i++)
            {
                tag.Add("Inventory_" + i + "_exists_" + UniqueID, this.Inventory[i].type != 0);
                if (this.Inventory[i].type != 0)
                {
                    tag.Add("Inventory_" + i + "_" + UniqueID, this.Inventory[i]);
                }
            }
            int EquipmentsSize = Equipments.Length;

            tag.Add("EquipmentsSize_" + UniqueID, EquipmentsSize);
            for (int e = 0; e < EquipmentsSize; e++)
            {
                tag.Add("Equipment_" + e + "_exists_" + UniqueID, this.Equipments[e].type != 0);
                if (this.Equipments[e].type != 0)
                {
                    tag.Add("Equipment_" + e + "_" + UniqueID, this.Equipments[e]);
                }
            }
            int BuffCount = Buffs.Count;

            tag.Add("BuffCount_" + UniqueID, BuffCount);
            for (int b = 0; b < Buffs.Count; b++)
            {
                int ID = Buffs[b].ID, Time = Buffs[b].Time;
                if (ID < 0 || ID >= Main.maxBuffTypes)
                {
                    ID = Time = 0;
                }
                tag.Add("Buff_" + b + "_type_" + UniqueID, ID);
                tag.Add("Buff_" + b + "_time_" + UniqueID, Time);
            }
            int SkillCount = SkillList.Count;

            tag.Add("SkillCount_" + UniqueID, SkillCount);
            for (int s = 0; s < SkillCount; s++)
            {
                tag.Add("SkillType_" + s + "_" + UniqueID, SkillList[s].skillType.ToString());
                tag.Add("SkillLevel_" + s + "_" + UniqueID, SkillList[s].Level);
                tag.Add("SkillProgress_" + s + "_" + UniqueID, SkillList[s].Progress);
            }
            tag.Add("BodyDye_" + UniqueID, BodyDye.type);
            tag.Add("FatigueCount_" + UniqueID, (byte)Fatigue);
            tag.Add("InjuryCount_" + UniqueID, (byte)Injury);
            //request.Save(tag, UniqueID);
            request.Save(tag, "Request_" + UniqueID);

            /*tag.Add("HasExistenceTime_" + UniqueID, LifeTime.HasValue);
             * if(LifeTime.HasValue)
             *  tag.Add("ExistenceTime_" + UniqueID, LifeTime.Value.TotalSeconds);*/
            tag.Add("SkinID_" + UniqueID, SkinID);
            tag.Add("OutfitID_" + UniqueID, OutfitID);
            tag.Add("Coins_" + UniqueID, (int)_Coins - int.MaxValue);
            SaveCustom(tag, UniqueID);
            GuardianCommonStatus.SaveStatus(ID, ModID);
        }