Elin Modding Docs Doc
Loading...
Searching...
No Matches
AI_PlayMusic.cs
1using System;
2using System.Collections.Generic;
3using DG.Tweening;
4using UnityEngine;
5
6// Token: 0x02000200 RID: 512
7public class AI_PlayMusic : AIAct
8{
9 // Token: 0x06000E9A RID: 3738 RVA: 0x0006D5B2 File Offset: 0x0006B7B2
10 public static void CancelKeepPlaying()
11 {
12 if (AI_PlayMusic.keepPlaying)
13 {
14 SE.CancelAction();
15 AI_PlayMusic.keepPlaying = false;
16 AI_PlayMusic.playingTool = null;
17 }
18 }
19
20 // Token: 0x170003BD RID: 957
21 // (get) Token: 0x06000E9B RID: 3739 RVA: 0x0006D5CC File Offset: 0x0006B7CC
22 public override bool ShowProgress
23 {
24 get
25 {
26 return false;
27 }
28 }
29
30 // Token: 0x170003BE RID: 958
31 // (get) Token: 0x06000E9C RID: 3740 RVA: 0x0006D5CF File Offset: 0x0006B7CF
32 public override bool CancelWhenDamaged
33 {
34 get
35 {
36 return !AI_PlayMusic.ignoreDamage;
37 }
38 }
39
40 // Token: 0x170003BF RID: 959
41 // (get) Token: 0x06000E9D RID: 3741 RVA: 0x0006D5D9 File Offset: 0x0006B7D9
42 public override TargetType TargetType
43 {
44 get
45 {
46 if (this.tool != null && this.tool != EClass.pc.Tool)
47 {
48 return TargetType.Any;
49 }
50 return TargetType.Self;
51 }
52 }
53
54 // Token: 0x06000E9E RID: 3742 RVA: 0x0006D600 File Offset: 0x0006B800
55 public override IEnumerable<AIAct.Status> Run()
56 {
57 if (this.tool == null)
58 {
59 this.tool = (this.owner.IsPC ? this.owner.Tool : this.owner.things.Find<TraitToolMusic>());
60 }
61 if (this.tool == null && !this.owner.IsPCFaction && EClass.rnd(20) == 0)
62 {
63 this.tool = this.owner.AddThing(ThingGen.Create("lute", -1, -1), true, -1, -1);
64 }
65 if (this.tool == null)
66 {
67 yield return this.Cancel();
68 }
69 if (this.tool.parent is Zone)
70 {
71 yield return base.DoGoto(this.tool.pos, this.tool.pos.IsBlocked ? 1 : 0, false, null);
72 }
73 if (this.owner.IsPCC && EClass.game.config.preference.keepPlayingMusic)
74 {
75 AI_PlayMusic.keepPlaying = true;
76 AI_PlayMusic.playingTool = this.tool;
77 EInput.Consume(true, 10);
78 }
79 this.toolLv = 1;
80 string idSong = null;
81 KnownSong song = null;
82 this.playing = null;
83 this.score = 40;
84 this.gold = 0;
85 if (this.owner.IsPC && EClass.player.playingSong != null && EClass.player.playingSong.idTool == this.tool.id)
86 {
87 this.playing = EClass.player.playingSong;
88 idSong = EClass.player.playingSong.id;
89 song = EClass.player.knownSongs[EClass.player.playingSong.id];
90 }
91 if (this.playing == null)
92 {
93 string id = this.tool.id;
94 uint num = <PrivateImplementationDetails>.ComputeStringHash(id);
95 if (num <= 3078472054U)
96 {
97 if (num <= 1172811742U)
98 {
99 if (num <= 390330866U)
100 {
101 if (num != 63985367U)
102 {
103 if (num != 390330866U)
104 {
105 goto IL_627;
106 }
107 if (!(id == "harpsichord"))
108 {
109 goto IL_627;
110 }
111 idSong = "harpsichord_goldberg";
112 goto IL_637;
113 }
114 else
115 {
116 if (!(id == "taiko"))
117 {
118 goto IL_627;
119 }
120 idSong = "taiko";
121 goto IL_637;
122 }
123 }
124 else if (num != 773192040U)
125 {
126 if (num != 1172811742U)
127 {
128 goto IL_627;
129 }
130 if (!(id == "piano"))
131 {
132 goto IL_627;
133 }
134 idSong = "piano_kanon";
135 goto IL_637;
136 }
137 else
138 {
139 if (!(id == "guitar_ash"))
140 {
141 goto IL_627;
142 }
143 idSong = "guitar_caccini";
144 goto IL_637;
145 }
146 }
147 else if (num <= 2565162886U)
148 {
149 if (num != 2166422584U)
150 {
151 if (num != 2565162886U)
152 {
153 goto IL_627;
154 }
155 if (!(id == "trumpet"))
156 {
157 goto IL_627;
158 }
159 idSong = "trumpet_practice";
160 goto IL_637;
161 }
162 else if (!(id == "instrument_violin"))
163 {
164 goto IL_627;
165 }
166 }
167 else if (num != 2938588943U)
168 {
169 if (num != 3078472054U)
170 {
171 goto IL_627;
172 }
173 if (!(id == "guitar_efrond"))
174 {
175 goto IL_627;
176 }
177 idSong = "guitar_dusk";
178 goto IL_637;
179 }
180 else
181 {
182 if (!(id == "guitar"))
183 {
184 goto IL_627;
185 }
186 idSong = "guitar_air";
187 goto IL_637;
188 }
189 }
190 else if (num <= 3559073827U)
191 {
192 if (num <= 3438029316U)
193 {
194 if (num != 3163500768U)
195 {
196 if (num != 3438029316U)
197 {
198 goto IL_627;
199 }
200 if (!(id == "piano_gould"))
201 {
202 goto IL_627;
203 }
204 idSong = "piano_gould";
205 goto IL_637;
206 }
207 else
208 {
209 if (!(id == "mic"))
210 {
211 goto IL_627;
212 }
213 idSong = "mic_rachmaninoff";
214 goto IL_637;
215 }
216 }
217 else if (num != 3502455904U)
218 {
219 if (num != 3559073827U)
220 {
221 goto IL_627;
222 }
223 if (!(id == "panty"))
224 {
225 goto IL_627;
226 }
227 }
228 else
229 {
230 if (!(id == "harp"))
231 {
232 goto IL_627;
233 }
234 idSong = "harp_komori";
235 goto IL_637;
236 }
237 }
238 else if (num <= 3841196189U)
239 {
240 if (num != 3758837070U)
241 {
242 if (num != 3841196189U)
243 {
244 goto IL_627;
245 }
246 if (!(id == "lute"))
247 {
248 goto IL_627;
249 }
250 idSong = "guitar_sad";
251 goto IL_637;
252 }
253 else
254 {
255 if (!(id == "mokugyo"))
256 {
257 goto IL_627;
258 }
259 idSong = "mokugyo";
260 goto IL_637;
261 }
262 }
263 else if (num != 3981110062U)
264 {
265 if (num != 4124199536U)
266 {
267 if (num != 4156158084U)
268 {
269 goto IL_627;
270 }
271 if (!(id == "piano2"))
272 {
273 goto IL_627;
274 }
275 idSong = "piano_neko";
276 goto IL_637;
277 }
278 else
279 {
280 if (!(id == "stradivarius"))
281 {
282 goto IL_627;
283 }
284 idSong = "violin_furusato";
285 goto IL_637;
286 }
287 }
288 else
289 {
290 if (!(id == "cello"))
291 {
292 goto IL_627;
293 }
294 idSong = "cello_prelude";
295 goto IL_637;
296 }
297 idSong = "violin_chaconne";
298 goto IL_637;
299 IL_627:
300 idSong = "violin_chaconne";
301 IL_637:
302 if (this.owner.IsPC && EClass.player.knownSongs.ContainsKey(idSong))
303 {
304 song = EClass.player.knownSongs[idSong];
305 }
306 if (song == null)
307 {
308 song = new KnownSong();
309 if (this.owner.IsPC)
310 {
311 EClass.player.knownSongs[idSong] = song;
312 }
313 }
314 this.playing = new PlayingSong
315 {
316 id = idSong,
317 idTool = this.tool.id
318 };
319 if (this.owner.IsPC)
320 {
321 EClass.player.playingSong = this.playing;
322 }
323 }
324 if (this.owner.IsPC)
325 {
326 (EClass.Sound.GetData("Instrument/" + idSong) as BGMData).song.index = this.playing.index;
327 }
328 if (Application.isEditor && this.owner.IsPC)
329 {
330 song.lv += 10;
331 Debug.Log(song.lv);
332 }
333 List<Chara> reacted = new List<Chara>();
335 {
336 maxProgress = 15,
337 cancelWhenMoved = false,
338 showProgress = false,
339 canProgress = (() => this.tool != null && !this.tool.isDestroyed),
340 onProgressBegin = delegate()
341 {
342 this.owner.Say("music_start", this.owner, this.tool, null, null);
343 this.owner.ShowEmo(Emo.happy, 3f, false);
344 if (this.tool != null && this.tool.ExistsOnMap)
345 {
346 this.owner.LookAt(this.tool);
347 }
348 this.owner.PlayAnime(AnimeID.PlayMusic, false);
349 if (this.owner.IsPC)
350 {
351 bool flag = false;
352 if (this.playing.mistakes == 0 && this.playing.source && this.playing.source.isPlaying && this.playing.source.data.name == idSong)
353 {
354 SoundSource source = this.playing.source;
355 if (Mathf.Abs(source.source.time - (source.data as BGMData).song.parts[this.playing.index].start) < 2f && this.playing.source.source.volume >= 0.1f)
356 {
357 source.KeepPlay();
358 flag = true;
359 Debug.Log("keep:" + source.source.time.ToString());
360 }
361 else
362 {
363 EClass.Sound.Stop(source.data, 0.1f);
364 }
365 Debug.Log(this.playing.source);
366 }
367 if (!flag)
368 {
369 this.playing.source = this.owner.PlaySound("Instrument/" + idSong, 1f, true);
370 Debug.Log(this.playing.source);
371 }
372 this.playing.bgm = (this.playing.source.data as BGMData);
373 BGMData.Part part = this.playing.bgm.song.parts[this.playing.index];
374 if (!UISong.Instance)
375 {
376 Util.Instantiate<UISong>("UI/Util/UISong", EClass.ui.rectDynamicEssential);
377 }
378 UISong.Instance.SetSong(this.playing.source, this.playing.bgm, part);
379 if (EClass.Sound.currentBGM != null)
380 {
381 float num2 = 0.5f - 0.1f * (float)this.playing.index;
382 if (num2 < 0f)
383 {
384 num2 = 0f;
385 }
386 if (EClass.Sound.sourceBGM.volume > EClass.Sound.currentBGM.data.volume * num2)
387 {
388 EClass.Sound.sourceBGM.DOFade(EClass.Sound.currentBGM.data.volume * num2, 3f);
389 }
390 SoundManager.jingleTimer = part.duration / this.playing.bgm.pitch + this.playing.bgm.song.fadeIn + 2f;
391 }
392 }
393 },
394 onProgress = delegate(Progress_Custom p)
395 {
396 Msg.SetColor(Msg.colors.Ono);
397 this.owner.Say(Lang.GetList("music").RandomItem<string>(), null, null);
398 Msg.SetColor();
399 if (EClass.debug.enable && EClass.pc.job.id == "pianist")
400 {
401 song.lv = 10000;
402 }
403 if (p.progress > 2 && (EClass.rnd(100 + 50 * this.owner.Evalue(1405)) == 0 || EClass.rnd(4 + (int)MathF.Max(0f, (float)(song.lv - this.playing.index * 25 - this.playing.index * this.playing.index / 2))) == 0))
404 {
405 this.playing.mistakes++;
406 if (EClass.rnd(2) == 0)
407 {
408 base.<Run>g__LevelSong|0(2 + 2 * EClass.rnd(this.owner.Evalue(1405) + 1));
409 }
410 if (this.playing.mistakes >= 10)
411 {
412 this.playing.index = 0;
413 }
414 this.Cancel();
415 return;
416 }
417 foreach (Chara chara in EClass._map.ListCharasInCircle(this.owner.pos, 4f, true))
418 {
419 if (chara.conSleep != null && chara.ResistLv(957) <= 0)
420 {
421 chara.conSleep.Kill(false);
422 chara.ShowEmo(Emo.angry, 0f, true);
423 }
424 }
425 List<Chara> list = this.owner.pos.ListWitnesses(this.owner, 4, WitnessType.music, null);
426 int num2 = this.owner.Evalue(241) * (100 + this.toolLv) / 100;
427 int num3 = 0;
428 foreach (Chara chara2 in list)
429 {
430 if (this.owner == null)
431 {
432 break;
433 }
434 if (!reacted.Contains(chara2) && EClass.rnd(5) == 0)
435 {
436 if (this.owner.IsPCParty)
437 {
438 if (chara2.interest <= 0 || (EClass._zone is Zone_Music && (chara2.IsPCFaction || chara2.IsPCFactionMinion)))
439 {
440 continue;
441 }
442 chara2.interest -= EClass.rnd(10);
443 if (chara2.interest < 0)
444 {
445 chara2.Talk("musicBored", null, null, false);
446 continue;
447 }
448 }
449 if (EClass.rnd(num3 * num3) <= 30)
450 {
451 bool isMinion = chara2.IsMinion;
452 if (num2 < chara2.LV && EClass.rnd(2) == 0)
453 {
454 reacted.Add(chara2);
455 if (!isMinion)
456 {
457 this.score -= chara2.LV / 2 - 10;
458 }
459 if (EClass.rnd(2) == 0)
460 {
461 chara2.Talk("musicBad", null, null, false);
462 }
463 else
464 {
465 chara2.Say("musicBad", chara2, this.owner, null, null);
466 }
467 chara2.ShowEmo(Emo.sad, 0f, true);
468 this.owner.elements.ModExp(241, 10, false);
469 if (EClass.rnd(5) == 0)
470 {
471 this.ThrowReward(chara2, true);
472 }
473 num3++;
474 }
475 else if (EClass.rnd(num2 + 5) > EClass.rnd(chara2.LV * 5 + 1))
476 {
477 reacted.Add(chara2);
478 if (!isMinion)
479 {
480 this.score += EClass.rnd(chara2.LV / 2 + 5) + 5;
481 }
482 if (EClass.rnd(2) == 0)
483 {
484 chara2.Talk("musicGood", null, null, false);
485 }
486 else
487 {
488 chara2.Say("musicGood", chara2, this.owner, null, null);
489 }
490 chara2.ShowEmo(Emo.happy, 0f, true);
491 chara2.renderer.PlayAnime((EClass.rnd(2) == 0) ? AnimeID.Jump : AnimeID.Fishing, default(Vector3), false);
492 this.owner.elements.ModExp(241, 50, false);
493 if (!isMinion)
494 {
495 this.ThrowReward(chara2, false);
496 }
497 num3++;
498 }
499 }
500 }
501 }
502 if (this.owner != null && this.owner.IsPC && EClass.rnd(80) < num3)
503 {
504 this.owner.stamina.Mod(-1);
505 }
506 },
507 onProgressComplete = delegate()
508 {
509 if (EClass.rnd(2) == 0)
510 {
511 base.<Run>g__LevelSong|0(2);
512 }
513 if (this.playing.bgm)
514 {
515 this.playing.index++;
516 this.playing.mistakes = 0;
517 if (this.playing.index >= this.playing.bgm.song.parts.Count)
518 {
519 this.playing.index = 0;
520 }
521 this.playing.bgm.song.index = this.playing.index;
522 }
523 this.Evaluate();
524 }
525 }.SetDuration(26, 2);
526 yield return base.Do(seq, null);
527 yield break;
528 }
529
530 // Token: 0x06000E9F RID: 3743 RVA: 0x0006D610 File Offset: 0x0006B810
531 public void Evaluate()
532 {
533 if (this.owner.IsPC)
534 {
535 int num = Mathf.Clamp(this.score / 20 + 1, 0, 9);
536 this.owner.Say(Lang.GetList("music_result")[num], null, null);
537 if (this.gold > 0)
538 {
539 this.owner.Say("music_reward", this.owner, this.gold.ToString() ?? "", null);
540 }
541 if (EClass.rnd(3) != 0)
542 {
543 this.owner.stamina.Mod(-1);
544 }
545 QuestMusic questMusic = EClass.game.quests.Get<QuestMusic>();
546 if (questMusic != null)
547 {
548 questMusic.score += this.score;
549 questMusic.sumMoney += this.gold;
550 int num2 = num / 2 - 1;
551 if (num > 0)
552 {
553 SE.Play("clap" + num2.ToString());
554 }
555 }
556 }
557 }
558
559 // Token: 0x06000EA0 RID: 3744 RVA: 0x0006D700 File Offset: 0x0006B900
560 public void ThrowReward(Chara c, bool punish)
561 {
562 Thing thing = null;
563 int num = 1;
564 string text;
565 if (punish)
566 {
567 text = ((EClass.rnd(5) == 0) ? "rock" : "pebble");
568 if (!c.IsPCFactionOrMinion)
569 {
570 Thing thing2 = c.TryGetThrowable();
571 thing = ((thing2 != null) ? thing2.Split(1) : null);
572 }
573 }
574 else if (EClass.rnd(100) == 0)
575 {
576 text = "plat";
577 if (EClass.rnd(3) == 0)
578 {
579 text = "casino_coin";
580 }
581 if (EClass.rnd(3) == 0)
582 {
583 text = "gacha_coin";
584 }
585 }
586 else
587 {
588 num = (EClass.rnd(c.LV * 2 + 1) + 1) * (100 + this.toolLv * 2 + this.owner.Evalue(1405) * 10) / 100;
589 if (c.IsUnique)
590 {
591 num *= 2;
592 }
593 if (!(EClass._zone is Zone_Music))
594 {
595 if (num > 25)
596 {
597 num /= 2;
598 }
599 if (num > 50)
600 {
601 num /= 2;
602 }
603 if (num > 100)
604 {
605 num /= 2;
606 }
607 }
608 if (num < 1)
609 {
610 num = 1;
611 }
612 this.gold += num;
613 text = "money";
614 }
615 if (!this.owner.IsPCParty && !punish && text != "money")
616 {
617 return;
618 }
619 if (thing == null)
620 {
621 thing = ThingGen.Create(text, -1, -1).SetNum(num);
622 }
623 AI_PlayMusic.ignoreDamage = true;
624 ActThrow.Throw(c, this.owner.pos, thing, punish ? ThrowMethod.Punish : ThrowMethod.Reward, 0f);
625 AI_PlayMusic.ignoreDamage = false;
626 if (this.owner != null)
627 {
628 this.owner.TryPickGroundItem();
629 }
630 }
631
632 // Token: 0x06000EA1 RID: 3745 RVA: 0x0006D878 File Offset: 0x0006BA78
633 public override void OnCancel()
634 {
635 if (this.playing != null && this.playing.bgm)
636 {
637 this.playing.bgm.song.Fail(this.playing.source, this.playing.bgm);
638 if (UISong.Instance)
639 {
640 UISong.Instance.Kill();
641 }
642 this.playing.source = null;
643 SoundManager.jingleTimer = 1f;
644 }
645 this.score /= 2;
646 this.Evaluate();
647 }
648
649 // Token: 0x04000D57 RID: 3415
650 public static bool keepPlaying;
651
652 // Token: 0x04000D58 RID: 3416
653 public static Thing playingTool;
654
655 // Token: 0x04000D59 RID: 3417
656 public Thing tool;
657
658 // Token: 0x04000D5A RID: 3418
659 public static bool ignoreDamage;
660
661 // Token: 0x04000D5B RID: 3419
662 public PlayingSong playing;
663
664 // Token: 0x04000D5C RID: 3420
665 public int score;
666
667 // Token: 0x04000D5D RID: 3421
668 public int gold;
669
670 // Token: 0x04000D5E RID: 3422
671 public int toolLv;
672}
Definition AIAct.cs:7
Definition Chara.cs:12
Definition Msg.cs:7
Definition Thing.cs:10
Definition Zone.cs:14