Skip to content

Commit a3bc1a7

Browse files
authored
Add surrender option (#2217)
* Add surrender option - initial commit Change old commands to dev commands and add new commands Add SurrenderManager * Surrender - second commit * Surrender - improve poll end (not always wait for timer) * Surrender - fix tests and add comment * Fix tests 2 * Surrender - localize the text in the js + rename functions * Surrender - fix tests 3 * Surrender - fix tests 4 * Surrender - fix tests 5 * Surrender - fix tests 6 * Surrender - fix tests 7 * Add add_enemy_points command * Change Panorama for Yes/No pool * Move some Configurations to Settings.lua
1 parent 6505136 commit a3bc1a7

File tree

22 files changed

+355
-41
lines changed

22 files changed

+355
-41
lines changed

.luacheckrc

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ globals = { -- these globals can be set and accessed.
6161
"CAPTURE_START_COUNTDOWN",
6262
"CAPTURE_INTERVAL",
6363
"CAPTURE_LENTGH",
64+
"SURRENDER_MINIMUM_KILLS_BEHIND",
65+
"SURRENDER_REQUIRED_YES_VOTES",
66+
"SURRENDER_TIME_TO_DISPLAY"
6467
}
6568

6669
read_globals = { -- these globals can only be accessed.

content/panorama/layout/custom_game/custom_ui_manifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<CustomUIElement type="Hud" layoutfile="file://{resources}/layout/custom_game/discord.xml" />
9898
<CustomUIElement type="Hud" layoutfile="file://{resources}/layout/custom_game/precache.xml" />
9999
<CustomUIElement type="Hud" layoutfile="file://{resources}/layout/custom_game/bottle_announcement.xml" />
100+
<CustomUIElement type="Hud" layoutfile="file://{resources}/layout/custom_game/surrender.xml" />
100101
<CustomUIElement type="EndScreen" layoutfile="file://{resources}/layout/custom_game/multiteam_end_screen.xml" />
101102

102103
<!-- From Overthrow.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<root>
2+
<styles>
3+
<include src='file://{resources}/styles/hud/dota_hud_gg.css' />
4+
<include src='file://{resources}/styles/dotastyles.css' />
5+
<include src='file://{resources}/styles/custom_game/surrender.css' />
6+
</styles>
7+
<scripts>
8+
<include src="file://{resources}/scripts/custom_game/surrender.js"/>
9+
</scripts>
10+
<Panel class='Surrender' hittest='false'>
11+
<Panel id='SurrenderGG'>
12+
<Label id='Header' text='#DOTA_HeroGuideViewer_Vote' />
13+
<Label id='LoseCounter' text='#surrender_suggestion' />
14+
<Label id='Time' text='time_left' />
15+
<Button id='Yes' class='PopupButton' onactivate='SelectYes()' oncontextmenu='SelectYes()'>
16+
<Label text='#UI_Yes'/>
17+
</Button>
18+
<Button id='No' class='PopupButton' onactivate='SelectNo()' oncontextmenu='SelectNo()'>
19+
<Label text='#UI_No'/>
20+
</Button>
21+
</Panel>
22+
</Panel>
23+
</root>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
var isRunning = false;
4+
var timeout;
5+
var returnEventName;
6+
7+
(function () {
8+
GameEvents.Subscribe('show_yes_no_poll', Open);
9+
}());
10+
11+
function Open (data) {
12+
if (!isRunning && data != null && data.returnEventName != null && data.pollText != null && data.pollTimeout != null) {
13+
isRunning = true;
14+
returnEventName = data.returnEventName;
15+
$('#SurrenderGG').SetHasClass('Show', true);
16+
timeout = data.pollTimeout;
17+
ScheduleSetTime(timeout);
18+
}
19+
}
20+
21+
function ScheduleSetTime (time) {
22+
$('#Time').visible = true;
23+
$('#Time').text = time;
24+
$.Schedule(1, SetTime);
25+
}
26+
27+
function SetTime () {
28+
--timeout;
29+
if (timeout === 0) {
30+
SelectNo();
31+
} else if (isRunning) {
32+
ScheduleSetTime(timeout);
33+
}
34+
}
35+
36+
function SelectYes () { // eslint-disable-line no-unused-vars
37+
SendResult(1);
38+
}
39+
40+
function SelectNo () {
41+
SendResult(0);
42+
}
43+
44+
function SendResult (result) {
45+
if (isRunning) { // you can get here if the timer has run out
46+
$('#SurrenderGG').SetHasClass('Show', false);
47+
GameEvents.SendCustomGameEventToServer(returnEventName, {
48+
result: result
49+
});
50+
51+
isRunning = false;
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.Surrender
2+
{
3+
horizontal-align: center;
4+
}
5+
6+
#SurrenderGG
7+
{
8+
opacity: 0;
9+
transform: translateY( -20px );
10+
width: 500px;
11+
height: 300px;
12+
13+
margin-top: 64px;
14+
15+
horizontal-align: center;
16+
vertical-align: top;
17+
18+
background-color: gradient( linear, 0% 0%, 0% 100%, from ( #373737 ), to ( #171717 ) );
19+
border-radius: 8px;
20+
border: 2px solid #000000;
21+
22+
transition-property: opacity, transform;
23+
transition-duration: 0.2s;
24+
}
25+
26+
#SurrenderGG.Show
27+
{
28+
opacity: 1;
29+
}
30+
31+
#Yes
32+
{
33+
horizontal-align: left;
34+
vertical-align: bottom;
35+
margin-bottom: 10px;
36+
margin-left: 30px;
37+
}
38+
39+
#No
40+
{
41+
horizontal-align: right;
42+
vertical-align: bottom;
43+
margin-bottom: 10px;
44+
margin-right: 30px;
45+
}

docs/dota2tools/chatcommands.md

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Commands to be used for debugging and testing purposes, currently requires the g
3939
<br>
4040
-addpoints x - Adds specified number of points to the user's team. Adds 1 point if no number specified.
4141
<br>
42+
-add_enemy_points x - Adds specified number of points to the enemy team. Adds 1 point if no number specified.
43+
<br>
4244
-switchhero x - Switch hero. Accepts partial names. Uses internal names, so -switchhero obsidian switches to Outworld Devourer, because his internal name is obsidian_destroyer.
4345
<br>
4446
-loadout x - Gives a pre-determined set of items. -loadout tank gives max level Heart, Stoneskin, and Satanic Core. -loadout damage gives max level Daedalus, Desolator, and Moon Shard.

docs/lua/events.md

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Either "**short**" "**normal**" or "**long**"
5252
### ngp_selection
5353
Sent when a player has made their selection for a given Need/Greed/Pass instance.
5454

55+
### surrender_result
56+
Sent when a player has made their selection for a given surrender instance.
57+
5558
**id**
5659
Type: `string` or `number`
5760
Unique ID for this item instance
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//=============================================================================
2+
// Surrender information notifications
3+
//=============================================================================
4+
"surrender_suggestion" "Would you like to surrender?"
5+
"team_has_surrendered" "The {s:team_text} team surrendered!"

game/scripts/vscripts/components/creeps/spawner.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function CreepCamps:Init ()
3636

3737
Minimap:InitializeCampIcons()
3838

39-
ChatCommand:LinkCommand("-spawncamps", Dynamic_Wrap(self, 'CreepSpawnTimer'), self)
39+
ChatCommand:LinkDevCommand("-spawncamps", Dynamic_Wrap(self, 'CreepSpawnTimer'), self)
4040
end
4141

4242
function CreepCamps:SetPowerLevel (powerLevel)

game/scripts/vscripts/components/devcheats/commands.lua

+19-19
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
DevCheats = class({})
55

66
function DevCheats:Init()
7-
ChatCommand:LinkCommand("-help", Dynamic_Wrap(DevCheats, "Help"), self)
8-
ChatCommand:LinkCommand("-list", Dynamic_Wrap(DevCheats, "Help"), self)
9-
ChatCommand:LinkCommand("-print_modifiers", Dynamic_Wrap(DevCheats, "PrintModifiers"), self)
10-
ChatCommand:LinkCommand("-addbots", Dynamic_Wrap(DevCheats, "AddBots"), self)
11-
ChatCommand:LinkCommand("-nofog", Dynamic_Wrap(DevCheats, "DisableFog"), self)
12-
ChatCommand:LinkCommand("-fog", Dynamic_Wrap(DevCheats, "EnableFog"), self)
13-
ChatCommand:LinkCommand("-fixspawn", Dynamic_Wrap(DevCheats, "TeleportHeroesToFountain"), self)
14-
ChatCommand:LinkCommand("-getpos", Dynamic_Wrap(DevCheats, "PrintPosition"), self)
15-
ChatCommand:LinkCommand("-god", Dynamic_Wrap(DevCheats, "GodMode"), self)
16-
ChatCommand:LinkCommand("-disarm", Dynamic_Wrap(DevCheats, "ToggleDisarm"), self)
17-
ChatCommand:LinkCommand("-dagger", Dynamic_Wrap(DevCheats, "GiveDevDagger"), self)
18-
ChatCommand:LinkCommand("-core", Dynamic_Wrap(DevCheats, "GiveUpgradeCore"), self)
19-
ChatCommand:LinkCommand("-addability", Dynamic_Wrap(DevCheats, "AddAbility"), self)
20-
ChatCommand:LinkCommand("-give", Dynamic_Wrap(DevCheats, "GiveLevelledItem"), self)
21-
ChatCommand:LinkCommand("-loadout", Dynamic_Wrap(DevCheats, "GiveLoadout"), self)
22-
ChatCommand:LinkCommand("-scepter", Dynamic_Wrap(DevCheats, "GiveUltimateScepter"), self)
23-
ChatCommand:LinkCommand("-dagon", Dynamic_Wrap(DevCheats, "GiveDevDagon"), self)
24-
ChatCommand:LinkCommand("-switchhero", Dynamic_Wrap(DevCheats, "SwitchHero"), self)
25-
ChatCommand:LinkCommand("-lazer", Dynamic_Wrap(DevCheats, "AddDevAttack"), self)
7+
ChatCommand:LinkDevCommand("-help", Dynamic_Wrap(DevCheats, "Help"), self)
8+
ChatCommand:LinkDevCommand("-list", Dynamic_Wrap(DevCheats, "Help"), self)
9+
ChatCommand:LinkDevCommand("-print_modifiers", Dynamic_Wrap(DevCheats, "PrintModifiers"), self)
10+
ChatCommand:LinkDevCommand("-addbots", Dynamic_Wrap(DevCheats, "AddBots"), self)
11+
ChatCommand:LinkDevCommand("-nofog", Dynamic_Wrap(DevCheats, "DisableFog"), self)
12+
ChatCommand:LinkDevCommand("-fog", Dynamic_Wrap(DevCheats, "EnableFog"), self)
13+
ChatCommand:LinkDevCommand("-fixspawn", Dynamic_Wrap(DevCheats, "TeleportHeroesToFountain"), self)
14+
ChatCommand:LinkDevCommand("-getpos", Dynamic_Wrap(DevCheats, "PrintPosition"), self)
15+
ChatCommand:LinkDevCommand("-god", Dynamic_Wrap(DevCheats, "GodMode"), self)
16+
ChatCommand:LinkDevCommand("-disarm", Dynamic_Wrap(DevCheats, "ToggleDisarm"), self)
17+
ChatCommand:LinkDevCommand("-dagger", Dynamic_Wrap(DevCheats, "GiveDevDagger"), self)
18+
ChatCommand:LinkDevCommand("-core", Dynamic_Wrap(DevCheats, "GiveUpgradeCore"), self)
19+
ChatCommand:LinkDevCommand("-addability", Dynamic_Wrap(DevCheats, "AddAbility"), self)
20+
ChatCommand:LinkDevCommand("-give", Dynamic_Wrap(DevCheats, "GiveLevelledItem"), self)
21+
ChatCommand:LinkDevCommand("-loadout", Dynamic_Wrap(DevCheats, "GiveLoadout"), self)
22+
ChatCommand:LinkDevCommand("-scepter", Dynamic_Wrap(DevCheats, "GiveUltimateScepter"), self)
23+
ChatCommand:LinkDevCommand("-dagon", Dynamic_Wrap(DevCheats, "GiveDevDagon"), self)
24+
ChatCommand:LinkDevCommand("-switchhero", Dynamic_Wrap(DevCheats, "SwitchHero"), self)
25+
ChatCommand:LinkDevCommand("-lazer", Dynamic_Wrap(DevCheats, "AddDevAttack"), self)
2626
end
2727

2828
-- Print all modifiers on player's hero to console

game/scripts/vscripts/components/duels/duels.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ function Duels:Init ()
109109
end)
110110

111111
-- Add chat commands to force start and end duels
112-
ChatCommand:LinkCommand("-duel", Dynamic_Wrap(self, "StartDuel"), self)
113-
ChatCommand:LinkCommand("-end_duel", Dynamic_Wrap(self, "EndDuel"), self)
112+
ChatCommand:LinkDevCommand("-duel", Dynamic_Wrap(self, "StartDuel"), self)
113+
ChatCommand:LinkDevCommand("-end_duel", Dynamic_Wrap(self, "EndDuel"), self)
114114
end
115115

116116
function Duels:RegisterZone(zoneName)
@@ -613,4 +613,3 @@ function Duels:PlayerForDuel(playerId)
613613

614614
return foundIt
615615
end
616-

game/scripts/vscripts/components/duels/savestate.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ local function TestSaveAndLoadState(keys)
142142
end)
143143
end
144144

145-
ChatCommand:LinkCommand("-test_state", TestSaveAndLoadState, nil)
145+
ChatCommand:LinkDevCommand("-test_state", TestSaveAndLoadState, nil)
146146
export.PurgeDuelHighgroundBuffs = PurgeDuelHighgroundBuffs
147147
export.SaveState = SaveState
148148
export.ResetState = ResetState

game/scripts/vscripts/components/duels/teleport.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ local function TestSafeTeleport(keys)
101101
SafeTeleportAll(hero, Vector(0, 0, 0), 150)
102102
end
103103

104-
ChatCommand:LinkCommand("-test_tp", TestSafeTeleport, nil)
104+
ChatCommand:LinkDevCommand("-test_tp", TestSafeTeleport, nil)
105105
export.SafeTeleport = SafeTeleport
106106
export.SafeTeleportAll = SafeTeleportAll
107107

game/scripts/vscripts/components/index.lua

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require('components/points/index')
99
require('components/gold/index')
1010
require('components/zonecontrol/index')
1111
require('components/duels/index')
12+
require('components/surrender/index')
1213
require('components/boss/index')
1314
require('components/progression/index')
1415
require('components/courier/index')

game/scripts/vscripts/components/music/music.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Music:Init ()
1919
CustomNetTables:SetTableValue('music', 'mute', muteTable)
2020
--to recompile all music
2121

22-
ChatCommand:LinkCommand("-compile_music", Dynamic_Wrap(Music, "Recompile"), Music)
22+
ChatCommand:LinkDevCommand("-compile_music", Dynamic_Wrap(Music, "Recompile"), Music)
2323
-- register mute button receiver
2424
CustomGameEventManager:RegisterListener("music_mute", Dynamic_Wrap(self, "MuteHandler"))
2525
-- Start first song

game/scripts/vscripts/components/points/points.lua

+18-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ function PointsManager:Init ()
2727
end)
2828

2929
-- Register chat commands
30-
ChatCommand:LinkCommand("-addpoints", Dynamic_Wrap(PointsManager, "AddPointsCommand"), self)
31-
ChatCommand:LinkCommand("-kill_limit", Dynamic_Wrap(PointsManager, "SetLimitCommand"), self)
32-
ChatCommand:LinkCommand("-kill_limit", Dynamic_Wrap(PointsManager, "SetLimitCommand"), self)
30+
ChatCommand:LinkDevCommand("-addpoints", Dynamic_Wrap(PointsManager, "AddPointsCommand"), self)
31+
ChatCommand:LinkDevCommand("-add_enemy_points", Dynamic_Wrap(PointsManager, "AddEnemyPointsCommand"), self)
32+
ChatCommand:LinkDevCommand("-kill_limit", Dynamic_Wrap(PointsManager, "SetLimitCommand"), self)
33+
ChatCommand:LinkDevCommand("-kill_limit", Dynamic_Wrap(PointsManager, "SetLimitCommand"), self)
3334
end
3435

3536
function PointsManager:CheckWinCondition(teamID, points)
@@ -107,6 +108,20 @@ function PointsManager:SetLimit(killLimit)
107108
CustomNetTables:SetTableValue('team_scores', 'limit', {value = killLimit, name = self:GetGameLength() })
108109
end
109110

111+
function PointsManager:AddEnemyPointsCommand(keys)
112+
local text = string.lower(keys.text)
113+
local splitted = split(text, " ")
114+
local hero = PlayerResource:GetSelectedHeroEntity(keys.playerid)
115+
local teamID = hero:GetTeamNumber()
116+
if hero:GetTeamNumber() == DOTA_TEAM_GOODGUYS then
117+
teamID = DOTA_TEAM_BADGUYS
118+
else
119+
teamID = DOTA_TEAM_GOODGUYS
120+
end
121+
local pointsToAdd = tonumber(splitted[2]) or 1
122+
self:AddPoints(teamID, pointsToAdd)
123+
end
124+
110125
function PointsManager:AddPointsCommand(keys)
111126
local text = string.lower(keys.text)
112127
local splitted = split(text, " ")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Allows players to surrender if a certain points difference has been reached
2+
require('components/surrender/surrender')

0 commit comments

Comments
 (0)