Exemple #1
0
        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);
        }
Exemple #2
0
 public void RemoveWish(Wish wish)
 {
     if (wishes.Contains(wish))
     {
         wishes.Remove(wish);
         wish.PostRemoved();
     }
 }
Exemple #3
0
        private Wish TryGiveWishFromWishDefDirect(WishDef def, Pawn pawn)
        {
            Wish wish = (Wish)Activator.CreateInstance(def.wishClass);

            wish.def  = def;
            wish.pawn = pawn;
            wish.PostMake();
            return(!wish.makeFailed ? wish : null);
        }
Exemple #4
0
 public void DismissWish(Wish wish)
 {
     if (wishes.Count == 1)
     {
         tickWithoutWish = withoutWishCache + wish.ageTicks;
         bufferTick      = 0;
     }
     RemoveWish(wish);
     pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtMaker.MakeThought(HDThoughtDefOf.WishDenial, 0));
 }
Exemple #5
0
        private static string WishDescription(Wish wish)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(wish.DescriptionTitle);
            stringBuilder.AppendLine();
            stringBuilder.AppendLine();
            stringBuilder.AppendLine();
            stringBuilder.Append(wish.DescriptionToFulfill);
            stringBuilder.AppendLine();
            stringBuilder.AppendLine();
            stringBuilder.AppendLine();
            stringBuilder.Append(wish.DescriptionTime);

            return(stringBuilder.ToString());
        }
Exemple #6
0
 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();
     }
 }
Exemple #7
0
        private static bool DrawWish(Rect rect, Wish wish, Pawn pawn)
        {
            try
            {
                if (Mouse.IsOver(rect))
                {
                    Widgets.DrawHighlight(rect);
                    if (Input.GetMouseButtonUp(1))
                    {
                        Find.LetterStack.LettersListForReading.RemoveAll((Letter l) => (l as ChoiceLetter_Wish)?.wish == wish);
                        ChoiceLetter_Wish letter = (ChoiceLetter_Wish)LetterMaker.MakeLetter(TranslationKey.RECEIVE_WISH_LETTER.Translate(WishUtility.Def.tierSingular[wish.TierIndex], pawn.LabelShort, wish.LabelCap),
                                                                                             WishDescription(wish),
                                                                                             HDLetterDefOf.Wish,
                                                                                             wish.pawn);
                        letter.wish = wish;
                        Find.LetterStack.ReceiveLetter(letter);
                    }
                }
                if (Mouse.IsOver(rect))
                {
                    TooltipHandler.TipRegion(rect, new TipSignal(WishDescription(wish), 7291));
                }

                Text.WordWrap = false;
                Text.Anchor   = TextAnchor.MiddleLeft;
                Rect rect2 = new Rect(rect.x + 10f, rect.y, rectWidth, rect.height);
                rect2.yMin -= 3f;
                rect2.yMax += 3f;
                string text = wish.LabelCap;

                Widgets.Label(rect2, text);
                Text.Anchor   = TextAnchor.MiddleCenter;
                Text.WordWrap = true;
            }
            catch (Exception ex)
            {
                Log.ErrorOnce(string.Concat("HDream : Exception in DrawThoughtGroup for ", wish.def, " on ", pawn, ": ", ex.ToString()), 3452698);
            }
            return(true);
        }