Example #1
0
 public static void Open()
 {
     Main.playerInventory  = false;
     WindowPosition.X      = Main.screenWidth * 0.2f;
     WindowPosition.Y      = Main.screenHeight * 0.2f;
     WindowWidth           = Main.screenWidth - (int)WindowPosition.X * 2;
     WindowHeight          = Main.screenHeight - (int)WindowPosition.Y * 2;
     PossibleGuardianIDs   = MainMod.GetPossibleStarterGuardians();
     PossibleGuardianNames = new string[PossibleGuardianIDs.Length];
     for (int i = 0; i < PossibleGuardianIDs.Length; i++)
     {
         GuardianBase gb = GuardianBase.GetGuardianBase(PossibleGuardianIDs[i].ID, PossibleGuardianIDs[i].ModID);
         if (gb.InvalidGuardian)
         {
             PossibleGuardianNames[i] = "Corrupted Memory";
         }
         else
         {
             PossibleGuardianNames[i] = gb.Name;
         }
     }
     WindowActive = true;
     GameModeInfo = new string[] { "The Buddies Mode is a special game mode where you pick a companion you",
                                   "will play the game with since the beggining of your adventure, until forever.",
                                   "The companion you pick ranges from starter companions, to companions met by other player characters.",
                                   "You wont be able to dismiss It, and takes longer to have others following you, so think well.",
                                   "Becareful, having extra companions with your will reduce the buddy mode benefits.",
                                   "You have 12 in-game hours (12 real life minutes) to decide if you want to try It or not." };;
 }
Example #2
0
        public void AddGuardian(int ID)
        {
            Mod          mod = ModLoader.GetMod(modid);
            GuardianBase gd  = GuardianBase.GuardianDB(ID, mod);

            GuardianList.Add(ID, gd);
            gd.SetupShop(ID, modid);
        }
        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);
        }
Example #4
0
 public GuardianSprites(GuardianBase companionBase, Mod mod)
 {
     ReferedBase = companionBase;
     if (mod == null)
     {
         mod = MainMod.mod;
     }
     this.mod = mod;
 }
Example #5
0
        public static void CompanionDB(int ID, out GuardianBase gb) //Your very own companion DB.
        {
            switch (ID)
            {
            case GaomonID:             //Remember that constant I set above? I can use It as a value on this switch, to make It easier to find out who the id belongs.
                gb = new GaomonBase(); //Make a class for your companion, extending GuardianBase to create a companion, then set a new instance of it as the GuardianBase value returned.
                break;

            default:
                gb = new GuardianBase();     //Always set the value to a new GuardianBase when the ID doesn't leads to a companion, this will recognize the companion as a non existing companion.
                break;
            }
        }
        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);
                }
            }
        }
        public static void LoadShops(Terraria.ModLoader.IO.TagCompound tag, int ModVersion)
        {
            int ShopCount = tag.GetInt("Shop_Count");

            for (int s = 0; s < ShopCount; s++)
            {
                string       ShopTag    = "Shop_s" + s + ">";
                int          OwnerID    = tag.GetInt(ShopTag + "OwnerID");
                string       OwnerModID = tag.GetString(ShopTag + "OwnerModID");
                GuardianBase gb         = GuardianBase.GetGuardianBase(OwnerID, OwnerModID);
                GuardianShop shop       = GetShop(OwnerID, OwnerModID);
                if (shop == null)
                {
                    gb.SetupShop(OwnerID, OwnerModID);
                    shop = GetShop(OwnerID, OwnerModID);
                }
                if (shop != null)
                {
                    int ItemCount = tag.GetInt(ShopTag + "ItemCount");
                    for (int i = 0; i < ItemCount; i++)
                    {
                        string ItemTag = ShopTag + "i" + i + ">";
                        if (tag.GetBool(ItemTag + "hasitem"))
                        {
                            bool   IsModItem = tag.GetBool(ItemTag + "ismoditem");
                            string ItemInternalName = null, ItemModInternalName = null;
                            int    ItemID = 0;
                            if (IsModItem)
                            {
                                ItemInternalName    = tag.GetString(ItemTag + "itemname");
                                ItemModInternalName = tag.GetString(ItemTag + "itemmodname");
                            }
                            else
                            {
                                ItemID = tag.GetInt(ItemTag + "itemid");
                            }
                            foreach (GuardianShopItem item in shop.Items)
                            {
                                if (item.ItemID == 0)
                                {
                                    continue;
                                }
                                if (ItemInternalName != null)
                                {
                                    Item anotheritem = new Item();
                                    anotheritem.SetDefaults(item.ItemID, true);
                                    if (anotheritem.modItem == null || anotheritem.modItem.Name != ItemInternalName || anotheritem.modItem.mod.Name != ItemModInternalName)
                                    {
                                        continue;
                                    }
                                }
                                else if (ItemID != item.ItemID)
                                {
                                    continue;
                                }
                                item.SaleTime      = tag.GetInt(ItemTag + "saletime");
                                item.TimedSaleTime = tag.GetInt(ItemTag + "timedsaletime");
                                item.Stack         = tag.GetInt(ItemTag + "stack");
                                break;
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        /// <summary>
        ///     Removes the guardian.
        /// </summary>
        /// <param name="guardianBase">The guardian.</param>
        public OrbwalkingChild RemoveGuardian(GuardianBase guardianBase)
        {
            this.Guardians.Remove(guardianBase);

            return(this);
        }
Example #9
0
        /// <summary>
        ///     Adds the specified guardian
        /// </summary>
        /// <param name="guardianBase">The guardian.</param>
        /// <returns></returns>
        public OrbwalkingChild Guardian(GuardianBase guardianBase)
        {
            this.Guardians.Add(guardianBase);

            return(this);
        }
Example #10
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;
                        }
                    }
                }
            }
        }