Elin Decompiled Documentation EA 23.130 Nightly
Loading...
Searching...
No Matches
AI_PlayMusic.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using DG.Tweening;
4using UnityEngine;
5
6public class AI_PlayMusic : AIAct
7{
8 public static bool keepPlaying;
9
10 public static Thing playingTool;
11
12 public Thing tool;
13
14 public static bool ignoreDamage;
15
17
18 public int score;
19
20 public int gold;
21
22 public int toolLv;
23
24 public override bool ShowProgress => false;
25
26 public override bool CancelWhenDamaged => !ignoreDamage;
27
28 public override TargetType TargetType
29 {
30 get
31 {
32 if (tool != null && tool != EClass.pc.Tool)
33 {
34 return TargetType.Any;
35 }
36 return TargetType.Self;
37 }
38 }
39
40 public static void CancelKeepPlaying()
41 {
42 if (keepPlaying)
43 {
44 SE.CancelAction();
45 keepPlaying = false;
46 playingTool = null;
47 }
48 }
49
50 public override IEnumerable<Status> Run()
51 {
52 if (tool == null)
53 {
54 tool = (owner.IsPC ? owner.Tool : owner.things.Find<TraitToolMusic>());
55 }
56 if (tool == null && !owner.IsPCFaction && EClass.rnd(20) == 0)
57 {
59 }
60 if (tool == null)
61 {
62 yield return Cancel();
63 }
64 if (tool.parent is Zone)
65 {
66 yield return DoGoto(tool.pos, tool.pos.IsBlocked ? 1 : 0);
67 }
69 {
70 keepPlaying = true;
72 EInput.Consume(consumeAxis: true, 10);
73 }
74 toolLv = 1;
75 string idSong = null;
76 KnownSong song = null;
77 playing = null;
78 score = 40;
79 gold = 0;
81 {
83 idSong = EClass.player.playingSong.id;
85 }
86 if (playing == null)
87 {
88 switch (tool.id)
89 {
90 case "trumpet":
91 idSong = "trumpet_practice";
92 break;
93 case "piano_gould":
94 idSong = "piano_gould";
95 break;
96 case "piano2":
97 idSong = "piano_neko";
98 break;
99 case "piano":
100 idSong = "piano_kanon";
101 break;
102 case "harpsichord":
103 idSong = "harpsichord_goldberg";
104 break;
105 case "guitar_ash":
106 idSong = "guitar_caccini";
107 break;
108 case "guitar_efrond":
109 idSong = "guitar_dusk";
110 break;
111 case "guitar":
112 idSong = "guitar_air";
113 break;
114 case "harp":
115 idSong = "harp_komori";
116 break;
117 case "lute":
118 idSong = "guitar_sad";
119 break;
120 case "recorder":
121 idSong = "recorder";
122 break;
123 case "flute":
124 idSong = "flute";
125 break;
126 case "taiko":
127 idSong = "taiko";
128 break;
129 case "mokugyo":
130 idSong = "mokugyo";
131 break;
132 case "tambourine":
133 idSong = "tambourine";
134 break;
135 case "mic":
136 idSong = "mic_rachmaninoff";
137 break;
138 case "cello":
139 idSong = "cello_prelude";
140 break;
141 case "instrument_violin":
142 case "panty":
143 idSong = "violin_chaconne";
144 break;
145 case "stradivarius":
146 idSong = "violin_furusato";
147 break;
148 default:
149 idSong = "violin_chaconne";
150 break;
151 }
152 if (owner.IsPC && EClass.player.knownSongs.ContainsKey(idSong))
153 {
154 song = EClass.player.knownSongs[idSong];
155 }
156 if (song == null)
157 {
158 song = new KnownSong();
159 if (owner.IsPC)
160 {
161 EClass.player.knownSongs[idSong] = song;
162 }
163 }
164 playing = new PlayingSong
165 {
166 id = idSong,
167 idTool = tool.id
168 };
169 if (owner.IsPC)
170 {
171 EClass.player.playingSong = playing;
172 }
173 }
174 if (owner.IsPC)
175 {
176 (EClass.Sound.GetData("Instrument/" + idSong) as BGMData).song.index = playing.index;
177 }
178 if (Application.isEditor && owner.IsPC)
179 {
180 song.lv += 10;
181 Debug.Log(song.lv);
182 }
183 List<Chara> reacted = new List<Chara>();
185 {
186 maxProgress = 15,
187 cancelWhenMoved = false,
188 showProgress = false,
189 canProgress = () => tool != null && !tool.isDestroyed,
190 onProgressBegin = delegate
191 {
192 owner.Say("music_start", owner, tool);
193 owner.ShowEmo(Emo.happy, 3f, skipSame: false);
194 if (tool != null && tool.ExistsOnMap)
195 {
197 }
198 owner.PlayAnime(AnimeID.PlayMusic);
199 if (owner.IsPC)
200 {
201 bool flag = false;
202 if (playing.mistakes == 0 && (bool)playing.source && playing.source.isPlaying && playing.source.data.name == idSong)
203 {
204 SoundSource soundSource = playing.source;
205 if (Mathf.Abs(soundSource.source.time - (soundSource.data as BGMData).song.parts[playing.index].start) < 2f && playing.source.source.volume >= 0.1f)
206 {
207 soundSource.KeepPlay();
208 flag = true;
209 Debug.Log("keep:" + soundSource.source.time);
210 }
211 else
212 {
213 EClass.Sound.Stop(soundSource.data, 0.1f);
214 }
215 Debug.Log(playing.source);
216 }
217 if (!flag)
218 {
219 playing.source = owner.PlaySound("Instrument/" + idSong);
220 Debug.Log(playing.source);
221 }
222 playing.bgm = playing.source.data as BGMData;
223 BGMData.Part part = playing.bgm.song.parts[playing.index];
224 if (!UISong.Instance)
225 {
226 Util.Instantiate<UISong>("UI/Util/UISong", EClass.ui.rectDynamicEssential);
227 }
229 if (EClass.Sound.currentBGM != null)
230 {
231 float num3 = 0.5f - 0.1f * (float)playing.index;
232 if (num3 < 0f)
233 {
234 num3 = 0f;
235 }
236 if (EClass.Sound.sourceBGM.volume > EClass.Sound.currentBGM.data.volume * num3)
237 {
238 EClass.Sound.sourceBGM.DOFade(EClass.Sound.currentBGM.data.volume * num3, 3f);
239 }
240 SoundManager.jingleTimer = part.duration / playing.bgm.pitch + playing.bgm.song.fadeIn + 2f;
241 }
242 }
243 },
244 onProgress = delegate(Progress_Custom p)
245 {
247 owner.Say(Lang.GetList("music").RandomItem());
248 Msg.SetColor();
249 if (tool.id == "tambourine")
250 {
251 Msg.Say("tambourine");
252 }
253 if (EClass.debug.enable && EClass.pc.job.id == "pianist")
254 {
255 song.lv = 10000;
256 }
257 if (p.progress > 2 && (EClass.rnd(100 + 50 * owner.Evalue(1405)) == 0 || EClass.rnd(4 + (int)MathF.Max(0f, song.lv - playing.index * 25 - playing.index * playing.index / 2)) == 0))
258 {
260 if (EClass.rnd(2) == 0)
261 {
262 LevelSong(2 + 2 * EClass.rnd(owner.Evalue(1405) + 1));
263 }
264 if (playing.mistakes >= 10)
265 {
266 playing.index = 0;
267 }
268 Cancel();
269 }
270 else
271 {
273 {
274 if (item.conSleep != null && item.ResistLv(957) <= 0)
275 {
276 item.conSleep.Kill();
277 item.ShowEmo(Emo.angry);
278 }
279 }
280 List<Chara> list = owner.pos.ListWitnesses(owner, 4, WitnessType.music);
281 int num = owner.Evalue(241) * (100 + toolLv) / 100;
282 int num2 = 0;
283 foreach (Chara item2 in list)
284 {
285 if (owner == null)
286 {
287 break;
288 }
289 if (!reacted.Contains(item2) && EClass.rnd(5) == 0)
290 {
291 if (owner.IsPCParty)
292 {
293 if (item2.interest <= 0 || (EClass._zone is Zone_Music && (item2.IsPCFaction || item2.IsPCFactionMinion)))
294 {
295 continue;
296 }
297 item2.interest -= EClass.rnd(10);
298 if (item2.interest < 0)
299 {
300 item2.Talk("musicBored");
301 continue;
302 }
303 }
304 if (EClass.rnd(num2 * num2) <= 30 && item2.pos.FirstChara == item2)
305 {
306 bool isMinion = item2.IsMinion;
307 if (num < item2.LV && EClass.rnd(2) == 0)
308 {
309 reacted.Add(item2);
310 if (!isMinion)
311 {
312 score -= item2.LV / 2 - 10;
313 }
314 if (EClass.rnd(2) == 0)
315 {
316 item2.Talk("musicBad");
317 }
318 else
319 {
320 item2.Say("musicBad", item2, owner);
321 }
322 item2.ShowEmo(Emo.sad);
323 owner.elements.ModExp(241, 10);
324 if (EClass.rnd(5) == 0)
325 {
326 ThrowReward(item2, punish: true);
327 }
328 num2++;
329 }
330 else if (EClass.rnd(num + 5) > EClass.rnd(item2.LV * 5 + 1))
331 {
332 reacted.Add(item2);
333 if (!isMinion)
334 {
335 score += EClass.rnd(item2.LV / 2 + 5) + 5;
336 }
337 if (EClass.rnd(2) == 0)
338 {
339 item2.Talk("musicGood");
340 }
341 else
342 {
343 item2.Say("musicGood", item2, owner);
344 }
345 item2.ShowEmo(Emo.happy);
346 item2.renderer.PlayAnime((EClass.rnd(2) == 0) ? AnimeID.Jump : AnimeID.Fishing);
347 owner.elements.ModExp(241, EClass._zone.IsUserZone ? 10 : 50);
348 if (!isMinion)
349 {
350 ThrowReward(item2, punish: false);
351 }
352 num2++;
353 }
354 }
355 }
356 }
357 if (owner != null && owner.IsPC && EClass.rnd(80) < num2)
358 {
359 owner.stamina.Mod(-1);
360 }
361 }
362 },
363 onProgressComplete = delegate
364 {
365 if (EClass.rnd(2) == 0)
366 {
367 LevelSong(2);
368 }
369 if ((bool)playing.bgm)
370 {
371 playing.index++;
372 playing.mistakes = 0;
373 if (playing.index >= playing.bgm.song.parts.Count)
374 {
375 playing.index = 0;
376 }
377 playing.bgm.song.index = playing.index;
378 }
379 Evaluate(success: true);
380 }
381 }.SetDuration(26);
382 yield return Do(seq);
383 void LevelSong(int a)
384 {
385 if (a > 0)
386 {
387 song.lv += a + EClass.rnd(2);
388 if (owner == EClass.pc)
389 {
390 Msg.Say("level_song");
391 }
392 }
393 }
394 }
395
396 public void Evaluate(bool success)
397 {
398 if (owner == null || !owner.IsPC)
399 {
400 return;
401 }
402 if (success)
403 {
404 score = score * 110 / 100;
405 }
406 else
407 {
408 score = score / 2 - 20;
409 }
410 int num = Mathf.Clamp(score / 20 + 1, 0, 9);
411 owner.Say(Lang.GetList("music_result")[num]);
412 if (gold > 0)
413 {
414 owner.Say("music_reward", owner, gold.ToString() ?? "");
415 }
416 if (EClass.rnd(3) != 0)
417 {
418 owner.stamina.Mod(-1);
419 }
420 QuestMusic questMusic = EClass.game.quests.Get<QuestMusic>();
421 if (questMusic != null)
422 {
423 questMusic.score += score;
424 questMusic.sumMoney += gold;
425 int num2 = num / 2 - 1;
426 if (num > 0)
427 {
428 SE.Play("clap" + num2);
429 }
430 }
431 }
432
433 public void ThrowReward(Chara c, bool punish)
434 {
435 Thing thing = null;
436 string text = "";
437 int num = 1;
438 if (punish)
439 {
440 text = ((EClass.rnd(5) == 0) ? "rock" : "pebble");
441 if (EClass.rnd(8) == 0)
442 {
443 text = ((EClass.rnd(3) == 0) ? "water_dirty" : "water");
444 }
445 if (!c.IsPCFactionOrMinion)
446 {
447 thing = c.TryGetThrowable()?.Split(1);
448 }
449 }
450 else if (EClass.rnd(100) == 0 && !EClass._zone.IsUserZone)
451 {
452 text = "ecopo";
453 if (EClass.rnd(4) == 0)
454 {
455 text = "gacha_coin";
456 }
457 if (EClass.rnd(4) == 0)
458 {
459 text = "plat";
460 }
461 if (EClass.rnd(3) == 0)
462 {
463 text = "tomato";
464 }
465 if (EClass.rnd(3) == 0)
466 {
467 text = "casino_coin";
468 }
469 }
470 else
471 {
472 num = (EClass.rnd(c.LV * 2 + 1) + 1) * (100 + toolLv * 2 + owner.Evalue(1405) * 10) / 100;
473 if (c.IsUnique)
474 {
475 num *= 2;
476 }
477 if (!(EClass._zone is Zone_Music))
478 {
479 if (num > 25)
480 {
481 num /= 2;
482 }
483 if (num > 50)
484 {
485 num /= 2;
486 }
487 if (num > 100)
488 {
489 num /= 2;
490 }
492 {
493 num /= 5;
494 }
495 }
496 if (num < 1)
497 {
498 num = 1;
499 }
500 gold += num;
501 text = "money";
502 }
503 if (!owner.IsPCParty && !punish && text != "money")
504 {
505 return;
506 }
507 if (thing == null)
508 {
509 thing = ThingGen.Create(text).SetNum(num);
510 }
511 ignoreDamage = true;
512 ActThrow.Throw(c, owner.pos, thing, (!punish) ? ThrowMethod.Reward : ThrowMethod.Punish);
513 ignoreDamage = false;
514 if (owner == null || !thing.ExistsOnMap)
515 {
516 return;
517 }
518 if (!owner.IsPC && owner.things.IsFull())
519 {
520 thing.Destroy();
521 return;
522 }
523 owner.Pick(thing);
524 if (thing.id == "money" && !owner.IsPC)
525 {
526 int num2 = (owner.Evalue(241) * 10 + 100) / ((owner.IsPCFaction && owner.memberType == FactionMemberType.Default) ? 1 : 10);
527 if (owner.GetCurrency() - num2 > 0)
528 {
529 owner.c_allowance += num;
530 owner.ModCurrency(-num);
531 }
532 }
533 }
534
535 public override void OnCancel()
536 {
537 if (playing != null && (bool)playing.bgm)
538 {
539 playing.bgm.song.Fail(playing.source, playing.bgm);
540 if ((bool)UISong.Instance)
541 {
543 }
544 playing.source = null;
545 SoundManager.jingleTimer = 1f;
546 }
547 Evaluate(success: false);
548 }
549}
AnimeID
Definition: AnimeID.cs:2
Emo
Definition: Emo.cs:2
FactionMemberType
ThrowMethod
Definition: ThrowMethod.cs:2
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
WitnessType
Definition: WitnessType.cs:2
Definition: AIAct.cs:6
Status Do(AIAct _seq, Func< Status > _onChildFail=null)
Definition: AIAct.cs:416
virtual Status Cancel()
Definition: AIAct.cs:291
new Chara owner
Definition: AIAct.cs:14
Status DoGoto(Point pos, int dist=0, bool ignoreConnection=false, Func< Status > _onChildFail=null)
Definition: AIAct.cs:432
int progress
Definition: AIProgress.cs:5
override bool CancelWhenDamaged
Definition: AI_PlayMusic.cs:26
override bool ShowProgress
Definition: AI_PlayMusic.cs:24
static Thing playingTool
Definition: AI_PlayMusic.cs:10
override IEnumerable< Status > Run()
Definition: AI_PlayMusic.cs:50
void ThrowReward(Chara c, bool punish)
static bool keepPlaying
Definition: AI_PlayMusic.cs:8
static void CancelKeepPlaying()
Definition: AI_PlayMusic.cs:40
override void OnCancel()
void Evaluate(bool success)
PlayingSong playing
Definition: AI_PlayMusic.cs:16
static bool ignoreDamage
Definition: AI_PlayMusic.cs:14
static EffectIRenderer Throw(Card c, Point p, Thing t, ThrowMethod method=ThrowMethod.Default, float failChance=0f)
Definition: ActThrow.cs:93
void PlayAnime(AnimeID id, bool force)
bool isDestroyed
Definition: Card.cs:71
bool IsPCFactionOrMinion
Definition: Card.cs:2172
Thing Split(int a)
Definition: Card.cs:3275
ElementContainerCard elements
Definition: Card.cs:37
string id
Definition: Card.cs:31
bool IsUnique
Definition: Card.cs:1991
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:5585
Thing Tool
Definition: Card.cs:2310
Thing AddThing(string id, int lv=-1)
Definition: Card.cs:2950
void Talk(string idTopic, string ref1=null, string ref2=null, bool forceSync=false)
Definition: Card.cs:6135
ICardParent parent
Definition: Card.cs:51
bool ExistsOnMap
Definition: Card.cs:1985
Thing SetNum(int a)
Definition: Card.cs:3286
Point pos
Definition: Card.cs:55
void ShowEmo(Emo _emo=Emo.none, float duration=0f, bool skipSame=true)
Definition: Card.cs:5553
void Destroy()
Definition: Card.cs:4680
ThingContainer things
Definition: Card.cs:34
int Evalue(int ele)
Definition: Card.cs:2471
void PlayAnime(AnimeID id, bool force=false)
Definition: Card.cs:5604
CardRenderer renderer
Definition: Card.cs:57
int LV
Definition: Card.cs:370
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:6232
Definition: Chara.cs:10
override bool IsPC
Definition: Chara.cs:602
SourceJob.Row job
Definition: Chara.cs:456
override bool IsPCParty
Definition: Chara.cs:605
int interest
Definition: Chara.cs:307
override bool IsMinion
Definition: Chara.cs:617
override bool IsPCFaction
Definition: Chara.cs:661
Thing TryGetThrowable()
Definition: Chara.cs:7102
override bool IsPCFactionMinion
Definition: Chara.cs:645
Stats stamina
Definition: Chara.cs:960
override void LookAt(Card c)
Definition: Chara.cs:3238
bool enable
Definition: CoreDebug.cs:285
Definition: EClass.cs:5
static Game game
Definition: EClass.cs:8
static int rnd(int a)
Definition: EClass.cs:58
static Zone _zone
Definition: EClass.cs:20
static Map _map
Definition: EClass.cs:18
static Player player
Definition: EClass.cs:12
static Chara pc
Definition: EClass.cs:14
static CoreDebug debug
Definition: EClass.cs:48
static SoundManager Sound
Definition: EClass.cs:46
static UI ui
Definition: EClass.cs:16
Definition: EInput.cs:8
static void Consume(int _skipFrame)
Definition: EInput.cs:656
void ModExp(int ele, int a, bool chain=false)
ConfigPreference preference
Definition: Game.cs:96
Config config
Definition: Game.cs:215
QuestManager quests
Definition: Game.cs:179
int lv
Definition: KnownSong.cs:6
Definition: Lang.cs:6
static string[] GetList(string id)
Definition: Lang.cs:114
List< Chara > ListCharasInCircle(Point center, float radius, bool los=true)
Definition: Map.cs:2269
Color Ono
Definition: MsgColors.cs:13
Definition: Msg.cs:5
static MsgColors colors
Definition: Msg.cs:20
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
static void SetColor()
Definition: Msg.cs:22
Dictionary< string, KnownSong > knownSongs
Definition: Player.cs:862
PlayingSong playingSong
Definition: Player.cs:1035
SoundSource source
Definition: PlayingSong.cs:13
string idTool
Definition: PlayingSong.cs:5
BGMData bgm
Definition: PlayingSong.cs:11
string id
Definition: PlayingSong.cs:3
int mistakes
Definition: PlayingSong.cs:9
List< Chara > ListWitnesses(Chara criminal, int radius=4, WitnessType type=WitnessType.crime, Chara target=null)
Definition: Point.cs:814
bool IsBlocked
Definition: Point.cs:351
Quest Get(string id)
virtual void Mod(int a)
Definition: Stats.cs:135
static TargetTypeSelf Self
Definition: TargetType.cs:7
static TargetTypeAny Any
Definition: TargetType.cs:5
Thing Find(int uid)
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
Definition: UISong.cs:5
void Kill()
Definition: UISong.cs:69
void SetSong(SoundSource _source, BGMData _bgm, BGMData.Part _part)
Definition: UISong.cs:29
static UISong Instance
Definition: UISong.cs:6
Definition: Zone.cs:12
virtual bool IsUserZone
Definition: Zone.cs:264