From: AriosJentu Date: Mon, 26 Aug 2019 11:51:18 +0000 (+1000) Subject: Add achievements for match place and most damage X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6e874e3ac734799b23ff0b11e2489f93e7fb2e59;p=xonotic%2Fxonotic-data.pk3dir.git Add achievements for match place and most damage --- diff --git a/qcsrc/common/achievements.qc b/qcsrc/common/achievements.qc index e9f3abacf..51be86530 100644 --- a/qcsrc/common/achievements.qc +++ b/qcsrc/common/achievements.qc @@ -23,6 +23,10 @@ void Achievements_set_achievement_value(entity this, string achieve, int value) if (achieve == "armageddon") this.armageddon = value; if (achieve == "firstblood") this.firstblood = value; + if (achieve == "firstplace") this.firstplace = value; + if (achieve == "secondplace") this.secondplace = value; + if (achieve == "thirdplace") this.thirdplace = value; + if (achieve == "mostdamage") this.mostdamage = value; if (achieve == "airshot") this.airshot = value; if (achieve == "amazing") this.amazing = value; @@ -50,6 +54,10 @@ int Achievements_get_achievement_value(entity this, string achieve) { if (achieve == "armageddon") return this.armageddon; if (achieve == "firstblood") return this.firstblood; + if (achieve == "firstplace") return this.firstplace; + if (achieve == "secondplace") return this.secondplace; + if (achieve == "thirdplace") return this.thirdplace; + if (achieve == "mostdamage") return this.mostdamage; if (achieve == "airshot") return this.airshot; if (achieve == "amazing") return this.amazing; @@ -77,6 +85,10 @@ string Achievements_get_achievement_title(string achieve) { if (achieve == "armageddon") return "Armageddon!"; if (achieve == "firstblood") return "First Blood!"; + if (achieve == "firstplace") return "First Place!"; + if (achieve == "secondplace") return "Second Place!"; + if (achieve == "thirdplace") return "Third Place!"; + if (achieve == "mostdamage") return "Most Damage!"; if (achieve == "airshot") return "Air Shot!"; if (achieve == "amazing") return "Amazing!"; diff --git a/qcsrc/common/achievements.qh b/qcsrc/common/achievements.qh index 87f158815..a916b26d0 100644 --- a/qcsrc/common/achievements.qh +++ b/qcsrc/common/achievements.qh @@ -15,6 +15,10 @@ CLASS(Achievements, Object) //Boolean achievements (can be set only once) ATTRIB(Achievements, firstblood, bool, 0); + ATTRIB(Achievements, firstplace, bool, 0); + ATTRIB(Achievements, secondplace, bool, 0); + ATTRIB(Achievements, thirdplace, bool, 0); + ATTRIB(Achievements, mostdamage, bool, 0); //Notificated achievements ATTRIB(Achievements, airshot, int, 0); @@ -30,6 +34,7 @@ CLASS(Achievements, Object) ATTRIB(Achievements, pointblank, int, 0); ATTRIB(Achievements, selfimmolation, int, 0); + //Getters and setters for achievements METHOD(Achievements, set_achievement_value, void(Achievements this, string achieve, int value)); METHOD(Achievements, get_achievement_value, int(Achievements this, string achieve)); diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index 8680b83a5..119dc59e5 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -1573,6 +1573,11 @@ void FixIntermissionClient(entity e) } } +void increase_achieve(entity player, string name) { + player.achievements.inc_achievement(player.achievements, name); + player.achievements.announce(player.achievements, player, name); +} + /* go to the next level for deathmatch only called if a time or frag limit has expired @@ -1626,6 +1631,46 @@ void NextLevel() MUTATOR_CALLHOOK(MatchEnd); localcmd("\nsv_hook_gameend\n"); + + + //Achievements + entity firstplace = spawn(); + entity secondplace = spawn(); + entity thirdplace = spawn(); + entity mostdamage = spawn(); + + FOREACH_CLIENT(IS_PLAYER(it), { + + if (!firstplace) { + firstplace = it; + } + + if (!mostdamage) { + mostdamage = it; + } + + float itaverage = PlayerScore_Get(it, SP_KILLS) / PlayerScore_Get(it, SP_SUICIDES); + float plaverage = PlayerScore_Get(firstplace, SP_KILLS) / PlayerScore_Get(firstplace, SP_SUICIDES); + bool cond = (firstplace.totalfrags == it.totalfrags && itaverage > plaverage); + + if (it.totalfrags > firstplace.totalfrags || cond) { + thirdplace = secondplace; + secondplace = firstplace; + firstplace = it; + } + + if (PlayerScore_Get(it, SP_DMG) > PlayerScore_Get(mostdamage, SP_DMG)) { + mostdamage = it; + } + + }); + + if (IS_PLAYER(firstplace)) increase_achieve(firstplace, "firstplace"); + if (IS_PLAYER(secondplace)) increase_achieve(secondplace, "secondplace"); + if (IS_PLAYER(thirdplace)) increase_achieve(thirdplace, "thirdplace"); + if (IS_PLAYER(mostdamage)) increase_achieve(mostdamage, "mostdamage"); + + }