-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
282 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require("lib.typescript"); | ||
// Link lua modifier | ||
LinkLuaModifier("modifier_panic", "modifiers/modifier_panic.lua", LuaModifierType.LUA_MODIFIER_MOTION_NONE); | ||
function Precache(context) { | ||
// Nothing to precache... | ||
} | ||
function Activate() { | ||
// Set general settings | ||
const mode = GameRules.GetGameModeEntity(); | ||
mode.SetFogOfWarDisabled(true); | ||
mode.SetCustomGameForceHero("npc_dota_hero_jakiro"); | ||
mode.SetWeatherEffectsDisabled(true); | ||
mode.SetCustomAttributeDerivedStatValue(AttributeDerivedStats.DOTA_ATTRIBUTE_AGILITY_ARMOR, 0); | ||
GameRules.SetHeroRespawnEnabled(false); | ||
// Listen for state change | ||
ListenToGameEvent("game_rules_state_change", OnStateChange, null); | ||
} | ||
function OnStateChange() { | ||
const state = GameRules.State_Get(); | ||
if (state == DOTA_GameState.DOTA_GAMERULES_STATE_PRE_GAME) { | ||
// Start game as soon as we hit the pregame | ||
StartGame(); | ||
} | ||
} | ||
function StartGame() { | ||
// Figure out who the players in the game are | ||
let players = []; | ||
for (let pID = 0; pID < DOTALimits_t.DOTA_MAX_TEAM_PLAYERS; pID++) { | ||
if (PlayerResource.IsValidPlayer(pID)) { | ||
players.push(pID); | ||
} | ||
} | ||
// Create instance of our game mode object | ||
const myGameMode = new MyGameMode(players); | ||
myGameMode.Init(); | ||
} | ||
class MyGameMode { | ||
constructor(players) { | ||
this.players = players; | ||
} | ||
Init() { | ||
// Print number of players | ||
print(`Starting game with ${this.players.length} players!`); | ||
// Listen for spawns | ||
ListenToGameEvent("npc_spawned", (event) => this.OnNpcSpawn(event), null); | ||
// Set ExecuteOrder filter | ||
GameRules.GetGameModeEntity().SetExecuteOrderFilter((ctx, order) => this.OnExecuteOrder(order), this); | ||
} | ||
OnNpcSpawn(event) { | ||
// Apply our lua modifier to the spawned unit | ||
// We can cast to npc since this is the 'npc_spawned' event | ||
const unit = EntIndexToHScript(event.entindex); | ||
unit.AddNewModifier(null, null, "modifier_panic", { duration: 8 }); | ||
} | ||
OnExecuteOrder(order) { | ||
print(order.order_type); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class modifier_panic extends CDOTA_Modifier_Lua { | ||
// Set state | ||
CheckState() { | ||
return { | ||
[modifierstate.MODIFIER_STATE_COMMAND_RESTRICTED]: true | ||
}; | ||
} | ||
// Declare functions | ||
DeclareFunctions() { | ||
return [ | ||
modifierfunction.MODIFIER_PROPERTY_MOVESPEED_ABSOLUTE | ||
]; | ||
} | ||
GetModifierMoveSpeed_Absolute() { return 540; } | ||
// Run when modifier instance is created | ||
OnCreated(params) { | ||
// Think every second | ||
this.StartIntervalThink(0.3); | ||
} | ||
// Called when intervalThink is triggered | ||
OnIntervalThink() { | ||
const parent = this.GetParent(); | ||
// Check if parent is not too far from origin | ||
if (parent.GetAbsOrigin().Length2D() < 500) { | ||
parent.MoveToPosition(parent.GetAbsOrigin() + RandomVector(400)); | ||
} | ||
else { | ||
// Otherwise redirect in the direction of the origin | ||
parent.MoveToPosition(RandomVector(300)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
function repeat(pattern, count) { | ||
if (count < 1) | ||
return ''; | ||
var result = ''; | ||
while (count > 1) { | ||
if (count & 1) | ||
result += pattern; | ||
count >>= 1, pattern += pattern; | ||
} | ||
return result + pattern; | ||
} | ||
function altDump(object) { | ||
$.Msg(`/* | ||
Typescript definition file of the DotA 2 Panorama API. | ||
This file contains information on the enums. This file can be used | ||
just as reference, or when writing Typescript to compile into Panorama JS. | ||
To use this file with typescript for Panorama, install typescript and put this file at the project root. | ||
Any javascript compiled from this typescript should be Panorama-compatible and run in Panorama. | ||
Issues or bugs in the definitions can be reported by making an issue on GitHub: | ||
https://github.com/ModDota/API. | ||
*/`); | ||
$.Msg(""); | ||
for (var v in object) { | ||
if (typeof object[v] == "object") { | ||
let i = 0; | ||
for (let w in object[v]) { | ||
if (typeof (object[v][w]) != "function") { | ||
i++; | ||
} | ||
} | ||
if (i > 0) { | ||
$.Msg("declare enum " + v + " {"); | ||
for (let w in object[v]) { | ||
/*if (i-- == 1) { | ||
$.Msg("Last entry test"); | ||
}*/ | ||
if (typeof (object[v][w]) != "function") { | ||
$.Msg(" " + w + " = " + ("" + object[v][w]) + ((i-- == 1) ? "" : ",")); | ||
} | ||
} | ||
$.Msg("}"); | ||
$.Msg(""); | ||
} | ||
} | ||
} | ||
} | ||
altDump(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const override_lua_server_json_1 = require("../_data/override_lua_server.json"); | ||
const lua_server_json_1 = require("../_data/lua_server.json"); | ||
const lua_server_enums_json_1 = require("../_data/lua_server_enums.json"); | ||
const primitives = [ | ||
"cstring", | ||
"int", | ||
"float", | ||
"bool", | ||
"vector", | ||
"void" | ||
]; | ||
const ReturnIDs = [ | ||
"CCustomGameEventListener", | ||
"PlayerID", | ||
"ParticleID", | ||
"EventListenerID", | ||
"ProjectileID", | ||
"CProjectileID" // EWW | ||
]; | ||
const numbers = [ | ||
"float", | ||
"int", | ||
"uint", | ||
"number" // Probably an error later down the track? | ||
]; | ||
function typeCompare(overrideType, baseType, className, funcName, argIndex) { | ||
if (overrideType.endsWith("!")) { | ||
console.warn(ValidationWarning(`${baseType} has been forceably casted to ${overrideType.slice(0, -1)}.`, className, funcName, argIndex)); | ||
return true; | ||
} | ||
switch (baseType.toLowerCase()) { | ||
case "<unknown>": | ||
case "table": | ||
// not manually casting <unknown> is considered a failure | ||
if (overrideType === baseType) { | ||
console.warn(ValidationWarning(`${baseType} should be casted to something more meaningful.`, className, funcName, argIndex)); | ||
} | ||
return true; | ||
case "int": | ||
case "uint": | ||
case "float": | ||
if (numbers.indexOf(overrideType) !== -1 && overrideType !== baseType) { | ||
console.warn(ValidationWarning(`${baseType} shouldn't be converted to ${overrideType}.`, className, funcName, argIndex)); | ||
return true; | ||
} | ||
return overrideType === baseType || Object.keys(lua_server_enums_json_1.default).indexOf(overrideType) !== -1 || ReturnIDs.indexOf(overrideType) !== -1; | ||
case "cstring": | ||
if (overrideType === "string") { | ||
console.warn(ValidationWarning(`${baseType} shouldn't be converted to ${overrideType}.`, className, funcName, argIndex)); | ||
return true; | ||
} | ||
case "uint64": | ||
case "bool": | ||
case "vector": | ||
case "qangle": | ||
case "void": | ||
return overrideType === baseType; | ||
case "handle": | ||
if (overrideType === baseType || overrideType === "table" || overrideType === "function") { | ||
console.warn(ValidationWarning(`${baseType} should be casted to something more meaningful.`, className, funcName, argIndex)); | ||
return true; | ||
} | ||
return overrideType.startsWith("fun(") || Object.keys(lua_server_json_1.default).indexOf(overrideType.replace("?", "").replace(" | nil", "")) !== -1; | ||
default: | ||
return false; | ||
} | ||
} | ||
const fails = []; | ||
let questions = 0; | ||
let nils = 0; | ||
const ValidationMessage = (message, className, funcName, argIndex) => { | ||
let argMsg = ""; | ||
if (argIndex !== undefined) { | ||
argMsg = ` arg ${argIndex}`; | ||
} | ||
if (argIndex === "return") { | ||
argMsg = " return"; | ||
} | ||
return `[${className}.${funcName || ""}${argMsg}] - ${message}`; | ||
}; | ||
const ValidationWarning = (message, className, funcName, argIndex) => "WARNING: " + ValidationMessage(message, className, funcName, argIndex); | ||
const ValidationError = (message, className, funcName, argIndex) => "ERROR: " + ValidationMessage(message, className, funcName, argIndex); | ||
function check(condidition, msg, className, funcName, argIndex) { | ||
if (!condidition) { | ||
fails.push(ValidationError(msg, className, funcName, argIndex)); | ||
} | ||
return condidition; | ||
} | ||
for (const className of Object.keys(override_lua_server_json_1.default)) { | ||
check(className in lua_server_json_1.default, "Overriding a class that doesn't exist", className); | ||
const baseClass = lua_server_json_1.default[className]; | ||
const overrideClass = override_lua_server_json_1.default[className]; | ||
// You might not be overriding functions | ||
if (typeof override_lua_server_json_1.default[className].functions === "object") { | ||
for (const funcName of Object.keys(override_lua_server_json_1.default[className].functions)) { | ||
check(funcName in baseClass.functions, "Overriding a function that doesn't exist", className, funcName); | ||
const baseFunc = baseClass.functions[funcName]; | ||
const overrideFunc = overrideClass.functions[funcName]; | ||
if (overrideFunc.return) { | ||
check(typeCompare(overrideFunc.return, baseFunc.return, className, funcName, "return"), `Overriden return is not compatible, expected ${baseFunc.return} but got ${overrideFunc.return}`, className, funcName, "return"); | ||
} | ||
if (check(baseFunc.args.length === overrideFunc.args.length, `Overriden args should have same length, expected ${baseFunc.args.length} but got ${overrideFunc.args.length}`, className, funcName)) { | ||
if (overrideFunc.arg_names && baseFunc.arg_names) { | ||
check(baseFunc.arg_names.length === overrideFunc.arg_names.length, `Overriden arg names should have same length, expected ${baseFunc.arg_names.length} but got ${overrideFunc.arg_names.length}`, className, funcName); | ||
} | ||
for (let i in baseFunc.args) { | ||
if (overrideFunc.args[i].endsWith("?")) { | ||
questions++; | ||
} | ||
if (overrideFunc.args[i].endsWith(" | nil")) { | ||
nils++; | ||
} | ||
let argName = i; | ||
if (baseFunc.arg_names) { | ||
argName = `"${baseFunc.arg_names[i]}"`; | ||
} | ||
if (overrideFunc.arg_names) { | ||
argName = `\`${overrideFunc.arg_names[i]}\``; | ||
} | ||
check(typeCompare(overrideFunc.args[i], baseFunc.args[i], className, funcName, argName), `Overriden argument type not compatible, expected ${baseFunc.args[i]} but got ${overrideFunc.args[i]}`, className, funcName, argName); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
for (let fail of fails) { | ||
console.error(fail.toString()); | ||
} | ||
console.table({ questions, nils }); | ||
process.exit(fails.length === 0 ? 0 : 1); |