/// <summary> /// Changes the inputted VillagerType's reputation by amount. /// </summary> /// <param name="villagerType">Enum of VillagerType</param> /// <param name="amount">Amount by which the reputation is changed</param> public static void ModifyReputation(VillagerType villagerType, int amount, bool wasGift = false) { if (villagerType >= 0 && villagerType < VillagerType.VillagerTypeCount) { villageReputation[(int)villagerType] += amount; if (wasGift) { villageGiftCooldown[(int)villagerType] = LivingWorldMod.villageGiftCooldownTime; } } }
/// <summary> /// Adds an item's gift value to the current gift progess. /// </summary> /// <param name="villagerType">Villager type to get the gifting progress of.</param> /// <param name="itemType">Gift's item type.</param> public static void AddGiftToProgress(VillagerType villagerType, int itemType) { int giftValue = LivingWorldMod.GetGiftValue(villagerType, itemType); int giftProgress = GetGiftProgress(villagerType); int shrineStage = GetShrineStage(villagerType); if (giftProgress + giftValue >= 100) { int remaining = (giftProgress + giftValue) - 100; if (shrineStage < 5) { SetShrineStage(villagerType, shrineStage + 1); SetGiftProgress(villagerType, remaining); } } else if (giftProgress + giftValue < 0) { int remaining = 0 - (giftProgress + giftValue); if (shrineStage >= 0) { SetShrineStage(villagerType, shrineStage - 1); SetGiftProgress(villagerType, 100 - remaining); } } else { SetGiftProgress(villagerType, giftProgress + giftValue); } //Setting default values and increasing reputation if it reaches max gift progress on last stage if (shrineStage == 5 && giftProgress + giftProgress >= 100) { SetGiftProgress(villagerType, 0); SetShrineStage(villagerType, 3); SetReputation(villagerType, GetReputation(villagerType) + 20); } //Increasing the gifted amount IncreaseGiftAmount(villagerType, itemType); }
protected override void DrawSelf(SpriteBatch spriteBatch) { VillagerType shrineType = ShrineUIPanel.shrineType; //int reputation = LWMWorld.GetReputation(shrineType); float quotient; if (giftMode) { int giftProgress = LWMWorld.GetGiftProgress(shrineType); text.SetText($"{giftProgress} / {maxProgress}"); quotient = giftProgress / (float)maxProgress; } else //stageMode { int shrineStage = LWMWorld.GetShrineStage(shrineType); text.SetText($"{shrineStage} / {maxProgress}"); quotient = shrineStage / (float)maxProgress; } quotient = Terraria.Utils.Clamp(quotient, 0f, 1f); Rectangle hitbox = barFrame.GetInnerDimensions().ToRectangle(); //Magic numbers to keep everything aligned hitbox.X += 2; hitbox.Width -= 4; int left = hitbox.Left; int right = hitbox.Right; int steps = (int)((right - left) * quotient); for (int i = 0; i < steps; i += 1) { //float percent = (float)i / steps; // Alternate Gradient Approach float percent = (float)i / (right - left); Color color = Color.Lerp(colorA, colorB, percent); spriteBatch.Draw(Main.magicPixel, new Rectangle(left + i, hitbox.Y, 1, hitbox.Height), color); } }
/// <summary> /// Changes the inputted VillagerType's reputation by amount, and creates a combat text by the changed amount at combatTextPosition. /// </summary> /// <param name="villagerType">Enum of VillagerType</param> /// <param name="amount">Amount by which the reputation is changed</param> /// <param name="combatTextPosition">Location of the combat text created to signify the changed reputation amount</param> public static void ModifyReputation(VillagerType villagerType, int amount, Rectangle combatTextPosition, bool wasGift = false) { if (villagerType >= 0 && villagerType < VillagerType.VillagerTypeCount) { villageReputation[(int)villagerType] += amount; if (wasGift) { villageGiftCooldown[(int)villagerType] = LivingWorldMod.villageGiftCooldownTime; } Color combatTextColor = Color.Lime; if (amount < 0) { combatTextColor = Color.Red; } else if (amount == 0) { combatTextColor = Color.Gray; } CombatText.NewText(combatTextPosition, combatTextColor, (amount >= 0 ? "+" : "") + amount + " Reputation", true); } }
/// <summary> /// Returns reputation absorption value of the given villager type. /// </summary> /// <param name="villagerType">Villager type to get the reputation absorption of.</param> public static int GetReputationAbsorption(VillagerType villagerType) => reputationAbsorption[(int)villagerType];
/// <summary> /// Modifies the gift value of a given item based on VillagerType. /// </summary> /// <param name="villagerType">The villager type to have their preference changed.</param> /// <param name="itemType">The item type that will have its gift value changed.</param> /// <param name="value">The new gift value of the given item type. Value between -5 and 5.</param> public static void SetGiftValue(VillagerType villagerType, int itemType, int value) { int index = (int)villagerType * ItemLoader.ItemCount + itemType; villageGiftPreferences[index] = Utils.Clamp(value, -5, 5); }
/// <summary> /// Returns the gift value a given item type will have on a given villager type. /// </summary> /// <param name="villagerType">The villager type to find the specific preference of.</param> /// <param name="itemType">The type of item to have its reputation modifier checked.</param> public static int GetGiftValue(VillagerType villagerType, int itemType) { int index = (int)villagerType * ItemLoader.ItemCount + itemType; return(villageGiftPreferences[index]); }
/// <summary> /// Returns the shrine stage of the given villager type shrine. /// </summary> /// <param name="villagerType">Villager type to get the shrine stage of.</param> public static int GetShrineStage(VillagerType villagerType) => shrineStage[(int)villagerType];
public static void TileRightClicked(int i, int j, VillagerType villageShrineType) { shrineType = villageShrineType; Instance.Toggle(); itemSlotPos = LWMUtils.FindMultiTileTopLeft(i, j, TileType <HarpyShrineTile>()) + new Vector2(-5, -11); }
/// <summary> /// Returns the gifting progress of the given villager type. /// </summary> /// <param name="villagerType">Villager type to get the gifting progress of.</param> public static int GetGiftProgress(VillagerType villagerType) => giftProgress[(int)villagerType];
/// <summary> /// Modifies the gifting progress of the given villager type. /// </summary> /// <param name="villagerType">Villager type to modify the gifting progress of.</param> /// <param name="amount">The amount to change the gifting progress by.</param> public static void SetGiftProgress(VillagerType villagerType, int amount) { amount = Utils.Clamp(amount, 0, 100); giftProgress[(int)villagerType] = amount; }
/// <summary> /// Increases the item's gifted amount by one. /// </summary> /// <param name="villagerType">Villager type to get the gifting progress of.</param> /// <param name="itemType">Gift's item type.</param> public static void IncreaseGiftAmount(VillagerType villagerType, int itemType) { int index = (int)villagerType * ItemLoader.ItemCount + itemType; itemGiftAmount[index]++; }
/// <summary> /// Returns the item's gifted amount. /// </summary> /// <param name="villagerType">Villager type to get the gifting progress of.</param> /// <param name="itemType">Gift's item type.</param> public static int GetGiftAmount(VillagerType villagerType, int itemType) { int index = (int)villagerType * ItemLoader.ItemCount + itemType; return(itemGiftAmount[index]); }
/// <summary> /// Changes the inputted VillagerType's reputation by amount. /// </summary> /// <param name="villagerType">Enum of VillagerType</param> /// <param name="amount">Amount by which the reputation is changed</param> public static void SetReputation(VillagerType villagerType, int amount) { amount = Utils.Clamp(amount, 0, LivingWorldMod.maximumReputationValue); reputation[(int)villagerType] = amount; }
//TODO: Multiplayer Compat. for the modification methods //TODO: reinitialize stuff in case there's no save file (fresh world) /// <summary> /// Returns reputation value of the given villager type. /// Also includes the reputation absorption of the given villager type, if applicable. /// </summary> /// <param name="villagerType">Villager type to get the reputation of.</param> public static int GetReputation(VillagerType villagerType) => Utils.Clamp(reputation[(int)villagerType] + reputationAbsorption[(int)villagerType], 0, LivingWorldMod.maximumReputationValue);
/// <summary> /// Returns the WORLD (Tile Pos * 16) coordinates of the given villager type's shrine. /// </summary> /// <param name="villagerType">Type of villager to get the shrine coords of.</param> public static Vector2 GetShrineWorldPosition(VillagerType villagerType) { return(shrineCoords[(int)villagerType] * 16); }
/// <summary> /// Returns the TILE coordinates of the given villager type's shrine. /// </summary> /// <param name="villagerType">Type of villager to get the shrine coords of.</param> public static Vector2 GetShrineTilePosition(VillagerType villagerType) { return(shrineCoords[(int)villagerType]); }
/// <summary> /// Returns whether the item was already gifted once or more. /// </summary> /// <param name="villagerType">Villager type to get the gifting progress of.</param> /// <param name="itemType">Gift's item type.</param> public static bool IsGiftDiscovered(VillagerType villagerType, int itemType) { int index = ItemLoader.ItemCount * itemType + (int)villagerType; return(GetGiftAmount(villagerType, itemType) >= 1); }
/// <summary> /// Changes the inputted VillagerType's reputation absorption by amount. /// </summary> /// <param name="villagerType">Enum of VillagerType</param> /// <param name="amount">Amount by which the absorption is changed</param> public static void SetReputationAbsorption(VillagerType villagerType, int amount) { reputationAbsorption[(int)villagerType] = amount; }
/// <summary> /// Modifies the shrine stage of the given villager type. /// </summary> /// <param name="villagerType">Villager type to modify the shrine stage of.</param> /// <param name="amount">The amount to change the shrine stage by.</param> public static void SetShrineStage(VillagerType villagerType, int amount) { amount = Utils.Clamp(amount, 0, 5); shrineStage[(int)villagerType] = amount; }