public static void AddTitleAndWish(Rect listingRect, Pawn pawn) { if (!WishUtility.CanHaveWish(pawn) || pawn.wishes() == null) { return; } offsetY = 0f; AddTitle(new Rect(titleOffsetX, offsetY, listingRect.width, titleHeight), TranslationKey.WISH_TITLE.Translate()); Text.Anchor = TextAnchor.MiddleLeft; if (pawn.wishes().wishes.NullOrEmpty()) { GUI.color = Color.gray; Widgets.Label(new Rect(15f, offsetY, listingRect.width - 21f, 20f), TranslationKey.WISH_NONE.Translate()); GUI.color = Color.white; offsetY += rectOffsetY; } else { for (int i = 0; i < pawn.wishes().wishes.Count; i++) { if (DrawWish(new Rect(0f, offsetY, listingRect.width - 16f, 20f), pawn.wishes().wishes[i], pawn)) { offsetY += rectOffsetY; } } } offsetY += blockOffset; AddTitle(new Rect(titleOffsetX, offsetY, listingRect.width, titleHeight), TranslationKey.MOOD_TITLE.Translate()); Text.Anchor = TextAnchor.UpperLeft; }
public Wish TryGiveWish() { if (!WishUtility.CanHaveWish(pawn)) { return(null); } List <WishDef> timeWishes = DefDatabase <WishDef> .AllDefsListForReading.FindAll(wish => wish.category == WishCategory.Time); for (int i = 0; i < timeWishes.Count; i++) { wishChances[timeWishes[i]] = timeWishes[i].GetChance(pawn); } for (int j = 0; j < wishChances.Count; j++) { if (!timeWishes.TryRandomElementByWeight((WishDef d) => wishChances[d], out WishDef result)) { break; } Wish wish = TryGiveWishFromWishDefDirect(result, pawn); if (wish != null) { return(wish); } wishChances[result] = 0f; } return(null); }
public void WishesTick() { if (!WishUtility.CanHaveWish(pawn)) { return; } if (!wishes.NullOrEmpty()) { for (int i = wishes.Count - 1; i >= 0; i--) { Wish wish = wishes[i]; wish.Tick(); wish.PostTick(); } DreamFeedback(); } if (pawn.IsHashIntervalTick(GenDate.TicksPerHour)) { if (Rand.Value <= WishUtility.ChancePerHourToGetNewWish(pawn)) { Wish wish = TryGiveWish(); if (wish != null) { wishes.Add(wish); wish.PostAdd(); Messages.Message(TranslationKey.MESSAGE_NEW_WISH.Translate(WishUtility.Def.tierSingular[wish.TierIndex], pawn.LabelShort, wish.LabelCap), new LookTargets(pawn), MessageTypeDefOf.CautionInput); if (depressionTick > 0) { pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(HDThoughtDefOf.NoWishDepresion); depressionTick = 0; } withoutWishCache = tickWithoutWish; tickWithoutWish = 0; bufferTick = (int)(WishUtility.Def.newWishBufferDepressionStartInDay * GenDate.TicksPerDay); } } } if (bufferTick > 0) { bufferTick--; } else { NoWishTime(); } }
public static float ResizeScroll(Pawn pawn, float height) { if (!WishUtility.CanHaveWish(pawn) || pawn.wishes() == null) { return(height); } height += titleHeight * 2 + blockOffset; if (!pawn.wishes().wishes.NullOrEmpty()) { height += (float)pawn.wishes().wishes.Count *rectOffsetY; } else { height += rectOffsetY; } return(height); }