From 1ec248eaa3c2ec48eb3410df53feacfe11f5b8c1 Mon Sep 17 00:00:00 2001 From: Vam-Jam Date: Fri, 16 Apr 2021 15:52:05 +0100 Subject: [PATCH] Init from linux --- CoreScripts/Character/BlobCharacter.as | 514 ++++++------ CoreScripts/Character/CharacterCore.as | 730 +++++++++--------- CoreScripts/Character/Configs/Kevin.cfg | 2 +- CoreScripts/Character/Configs/Soren.cfg | 2 +- .../Character/InteractableCharacter.as | 98 +-- CoreScripts/Events/EventCore.as | 138 ++-- CoreScripts/Events/EventSector.as | 304 ++++---- CoreScripts/Rules/CharacterHandler.as | 223 +++--- Maps/CommonScripts/MapsCore.as | 294 +++---- Maps/KnightShowcase/KnightShowcase.as | 198 ++--- Maps/Test/Test.as | 138 ++-- README.md | 14 +- TutorialMain.as | 360 ++++----- VanillaFixes/EmoteBubble.as | 166 ++-- gamemode.cfg | 122 +-- mapcycle.cfg | 2 +- 16 files changed, 1655 insertions(+), 1650 deletions(-) diff --git a/CoreScripts/Character/BlobCharacter.as b/CoreScripts/Character/BlobCharacter.as index a915b9a..e32a9cf 100644 --- a/CoreScripts/Character/BlobCharacter.as +++ b/CoreScripts/Character/BlobCharacter.as @@ -1,257 +1,257 @@ -#include "CharacterCore" - -////////////////////// -/// -/// BlobCharacter -/// -/// This class is attached to a blob that wants the Character class -/// This lets us do special stuff with the blob class -/// - Adding a potrait based on the head currently equiped -/// - Emoting -/// And some other stuff that i forgot about - -class BlobCharacter : Character -{ - // String key, func value - dictionary FunctionMap = dictionary(); - - string CharacterTextureFile = ""; - string HeadTextureFile = ""; - CBlob@ OwnerBlob; - - - - s32 HeadIndex = 0; - s32 Team = 0; - - // Not in use - u8 testFrame = 0; - - void AddFunction(string name, CallbackButtonFunc@ func) - { - FunctionMap.set(name, @func); - } - - CallbackButtonFunc@ getFunction(string name) - { - CallbackButtonFunc@ func; - FunctionMap.get(name, @func); - return func; - } - - BlobCharacter(CBlob@ owner, string name) - { - @OwnerBlob = owner; - - int team = owner.getTeamNum(); - SetName("$T_"+team+"$<"+name+">$T_D$"); - - owner.set("character", @this); - - // TODO MAYBE IN THE FUTURE (effort) - // -> Load current blob sprite if custom_body doesnt exist - // -> get frame data from there instead of making custom body - - if (owner.exists("custom_body")) - CharacterTextureFile = owner.get_string("custom_body"); - else - CharacterTextureFile = owner.getName() + (owner.getSexNum() == 0 ? "_male_body.png" : "_female_body.png"); - } - - void CustomUpdate() - { - Update(); - - // Keep watch to update when the char changes head - SetHeadData(); - - // Disabled for now, looks cursed as fuck - /*if (!FinishedWriting && CurrentRenderText.substr(CurrentRenderText.length -2, 1) != " ") - testFrame = 1; - else - testFrame = 0;*/ - } - - void SetHeadData() - { - HeadIndex = OwnerBlob.get_s32("head index"); - Team = OwnerBlob.get_s32("head team"); - HeadTextureFile = OwnerBlob.get_string("head texture"); - } - - void CustomRender() - { - RenderBox(); - CharacterPortrait(); - } - - // TODO: Character head is empty the first few ticks - void CharacterPortrait() - { - Vec2f topLeft(0, 0); - // Get character head pos - Vec2f headpos(topLeft.x - 10, topLeft.y - 26); - - GUI::DrawIcon(CharacterTextureFile, 0, Vec2f(12, 12), Vec2f(topLeft.x + 6, topLeft.y + 6), 4.0f, Team); - GUI::DrawIcon(HeadTextureFile, HeadIndex + testFrame, Vec2f(16, 16), headpos , 4.0f, Team); - } - - // Todo -> Find a better way to do this maybe? It works for now i guess (unsure why i dislike this) - void PushToGlobalHandler() - { - CBitStream@ cbs = CBitStream(); - cbs.write_u16(OwnerBlob.getNetworkID()); - - getRules().SendCommand(getRules().getCommandID("character_bound"), cbs); - } -} - - -class BlobCharacterHandler -{ - // List of all the blob characters in our game - array BlobList; - - // Character we are going to render - BlobCharacter@ CharacterToRender = null; - - BlobCharacterHandler() - { - } - - void AddCharacter(BlobCharacter@ character) - { - BlobList.push_back(character); - - if (g_debug > 0) - { - print("Adding character \"" + character.getName() + "\""); - } - } - - void RemoveCharacter(CBlob@ blob) - { - BlobCharacter@ character = null; - blob.get("character", @character); - - if (character is null) - { - error("RemoveCharacter with blob " + blob.getName() + - " is null, please only remove when blob has a character attached to it"); - return; - } - - if (CharacterToRender is character) - @CharacterToRender = null; - - - int index = getBlobIndex(character); - if (index != -1) - BlobList.erase(index); - } - - int getBlobIndex(BlobCharacter@ char) - { - for (int a = 0; a < BlobList.length; a++) - { - if (char is BlobList[a]) - { - return a; - } - } - - return -1; - } - - int getBlobIndex(CBlob@ blob) - { - for (int a = 0; a < BlobList.length; a++) - { - BlobCharacter@ char = BlobList[a]; - - if (char.OwnerBlob is blob) - { - return a; - } - } - - return -1; - } - - void AddCharacter(CBlob@ blob) - { - BlobCharacter@ character = null; - blob.get("character", @character); - - if (character is null) - { - error("AddCharacter with blob " + blob.getName() + - " is null, please create character before hand!"); - - return; - } - - AddCharacter(character); - } - - void SetBlobToRender(CBlob@ blob) - { - int index = getBlobIndex(blob); - if (index != -1) - { - if (CharacterToRender !is null) - CharacterToRender.ResetTalkVars(); - - blob.get("character", @CharacterToRender); - CharacterToRender.SetHeadData(); - } - } - - bool FindAndSetToSpeak() - { - for (int a = 0; a < BlobList.length; a++) - { - BlobCharacter@ char = BlobList[a]; - if (char !is null && char.CurrentlyInteracting) - { - @CharacterToRender = char; - return true; - } - } - - return false; - } - - void onTick() - { - if (CharacterToRender is null && !FindAndSetToSpeak()) - return; - - CharacterToRender.CustomUpdate(); - - if (!CharacterToRender.CurrentlyInteracting) - @CharacterToRender = @null; - } - - void onRender() - { - if (CharacterToRender is null) - return; - - CharacterToRender.CustomRender(); - } - - // Todo: some other stuff? - void Clear() - { - BlobList.clear(); - } -} - -////// Quick handles for scripts to use ////// -BlobCharacter@ getCharacter(CBlob@ blob) -{ - BlobCharacter@ character = null; - blob.get("character", @character); - return character; -} +#include "CharacterCore" + +////////////////////// +/// +/// BlobCharacter +/// +/// This class is attached to a blob that wants the Character class +/// This lets us do special stuff with the blob class +/// - Adding a potrait based on the head currently equiped +/// - Emoting +/// And some other stuff that i forgot about + +class BlobCharacter : Character +{ + // String key, func value + dictionary FunctionMap = dictionary(); + + string CharacterTextureFile = ""; + string HeadTextureFile = ""; + CBlob@ OwnerBlob; + + + + s32 HeadIndex = 0; + s32 Team = 0; + + // Not in use + u8 testFrame = 0; + + void AddFunction(string name, CallbackButtonFunc@ func) + { + FunctionMap.set(name, @func); + } + + CallbackButtonFunc@ getFunction(string name) + { + CallbackButtonFunc@ func; + FunctionMap.get(name, @func); + return func; + } + + BlobCharacter(CBlob@ owner, string name) + { + @OwnerBlob = owner; + + int team = owner.getTeamNum(); + SetName("$T_"+team+"$<"+name+">$T_D$"); + + owner.set("character", @this); + + // TODO MAYBE IN THE FUTURE (effort) + // -> Load current blob sprite if custom_body doesnt exist + // -> get frame data from there instead of making custom body + + if (owner.exists("custom_body")) + CharacterTextureFile = owner.get_string("custom_body"); + else + CharacterTextureFile = owner.getName() + (owner.getSexNum() == 0 ? "_male_body.png" : "_female_body.png"); + } + + void CustomUpdate() + { + Update(); + + // Keep watch to update when the char changes head + SetHeadData(); + + // Disabled for now, looks cursed as fuck + /*if (!FinishedWriting && CurrentRenderText.substr(CurrentRenderText.length -2, 1) != " ") + testFrame = 1; + else + testFrame = 0;*/ + } + + void SetHeadData() + { + HeadIndex = OwnerBlob.get_s32("head index"); + Team = OwnerBlob.get_s32("head team"); + HeadTextureFile = OwnerBlob.get_string("head texture"); + } + + void CustomRender() + { + RenderBox(); + CharacterPortrait(); + } + + // TODO: Character head is empty the first few ticks + void CharacterPortrait() + { + Vec2f topLeft(0, 0); + // Get character head pos + Vec2f headpos(topLeft.x - 10, topLeft.y - 26); + + GUI::DrawIcon(CharacterTextureFile, 0, Vec2f(12, 12), Vec2f(topLeft.x + 6, topLeft.y + 6), 4.0f, Team); + GUI::DrawIcon(HeadTextureFile, HeadIndex + testFrame, Vec2f(16, 16), headpos , 4.0f, Team); + } + + // Todo -> Find a better way to do this maybe? It works for now i guess (unsure why i dislike this) + void PushToGlobalHandler() + { + CBitStream@ cbs = CBitStream(); + cbs.write_u16(OwnerBlob.getNetworkID()); + + getRules().SendCommand(getRules().getCommandID("character_bound"), cbs); + } +} + + +class BlobCharacterHandler +{ + // List of all the blob characters in our game + array BlobList; + + // Character we are going to render + BlobCharacter@ CharacterToRender = null; + + BlobCharacterHandler() + { + } + + void AddCharacter(BlobCharacter@ character) + { + BlobList.push_back(character); + + if (g_debug > 0) + { + print("Adding character \"" + character.getName() + "\""); + } + } + + void RemoveCharacter(CBlob@ blob) + { + BlobCharacter@ character = null; + blob.get("character", @character); + + if (character is null) + { + error("RemoveCharacter with blob " + blob.getName() + + " is null, please only remove when blob has a character attached to it"); + return; + } + + if (CharacterToRender is character) + @CharacterToRender = null; + + + int index = getBlobIndex(character); + if (index != -1) + BlobList.erase(index); + } + + int getBlobIndex(BlobCharacter@ char) + { + for (int a = 0; a < BlobList.length; a++) + { + if (char is BlobList[a]) + { + return a; + } + } + + return -1; + } + + int getBlobIndex(CBlob@ blob) + { + for (int a = 0; a < BlobList.length; a++) + { + BlobCharacter@ char = BlobList[a]; + + if (char.OwnerBlob is blob) + { + return a; + } + } + + return -1; + } + + void AddCharacter(CBlob@ blob) + { + BlobCharacter@ character = null; + blob.get("character", @character); + + if (character is null) + { + error("AddCharacter with blob " + blob.getName() + + " is null, please create character before hand!"); + + return; + } + + AddCharacter(character); + } + + void SetBlobToRender(CBlob@ blob) + { + int index = getBlobIndex(blob); + if (index != -1) + { + if (CharacterToRender !is null) + CharacterToRender.ResetTalkVars(); + + blob.get("character", @CharacterToRender); + CharacterToRender.SetHeadData(); + } + } + + bool FindAndSetToSpeak() + { + for (int a = 0; a < BlobList.length; a++) + { + BlobCharacter@ char = BlobList[a]; + if (char !is null && char.CurrentlyInteracting) + { + @CharacterToRender = char; + return true; + } + } + + return false; + } + + void onTick() + { + if (CharacterToRender is null && !FindAndSetToSpeak()) + return; + + CharacterToRender.CustomUpdate(); + + if (!CharacterToRender.CurrentlyInteracting) + @CharacterToRender = @null; + } + + void onRender() + { + if (CharacterToRender is null) + return; + + CharacterToRender.CustomRender(); + } + + // Todo: some other stuff? + void Clear() + { + BlobList.clear(); + } +} + +////// Quick handles for scripts to use ////// +BlobCharacter@ getCharacter(CBlob@ blob) +{ + BlobCharacter@ character = null; + blob.get("character", @character); + return character; +} diff --git a/CoreScripts/Character/CharacterCore.as b/CoreScripts/Character/CharacterCore.as index 0f44009..0ff586f 100644 --- a/CoreScripts/Character/CharacterCore.as +++ b/CoreScripts/Character/CharacterCore.as @@ -1,366 +1,366 @@ -////////////////////// -/// -/// CharacterCore -/// -/// This holds the core class to character talking. -/// Currently not stable, everything is subject to change. -/// -/// The class is a mixin, which means another class can inherit everything from it -/// This is useful in this case so we can write less code - - -#include "EmotesCommon" - -const u16 KEYS_TO_TAKE = key_left | key_right | key_up | key_down | key_action1 | key_action2 | key_action3; - -mixin class Character -{ - // String key, string value - dictionary ResponseMap = dictionary(); - - // Maybe you want this character to have a custom font - // - Set your own custom font, used before rendering text - string PreferedFont = "pixeled"; - - // Custom character name, added to the start of the text render - // - Note: Will get changed at some point - string CharacterName = ""; - - // How fast should we write by default - // - Note: text cfg's can change this with "{S_NUM}" - int WriteSpeed = 1; - - // Are we done writing text? - // - Used to know if text is done updating - bool FinishedWriting = false; - - // We are interacting with a player - // - Used to end talking to the character (gui goes bye) - bool CurrentlyInteracting = false; - - // CurrentRenderOutput Total length including special tokens that are not outputted - // - Used when updating text so we can grab the correct substr - int TextRenderLength = 0; - - // Text render queue, when one is over done, the next will be pushed - string[] ActiveResponseQueue; - // Text that is currently on the screen - string CurrentRenderOutput = ""; - // The whole text that is being written to ^ - string CurrentText = ""; - - void SetName(string name) - { - CharacterName = name; - } - - void AddResponse(string eventName, string text) - { - ResponseMap.set(eventName, getTranslatedString(text)); - } - - // Both getResponses do the same thing, but give the string back in different ways - string getResponse(string eventName) - { - string text = ""; - ResponseMap.get(eventName, text); - return text; - } - - void GetResponse(string eventName, string &out text) - { - ResponseMap.get(eventName, text); - } - - void AddToResponseQueue(string eventName) - { - string response = getResponse(eventName); - if (response == "") - return; - - ActiveResponseQueue.push_back(response); - FrontToOutput(); - } - - void ClearResponseQueue() - { - ActiveResponseQueue.clear(); - } - - bool LoadNextInQueue() - { - if (ActiveResponseQueue.length < 2) - return false; - - RemoveFrontOfQueue(); - FrontToOutput(); - - return true; - } - - void RemoveFrontOfQueue() - { - if (ActiveResponseQueue.isEmpty()) - return; - - ActiveResponseQueue.erase(0); - } - - // Todo: rename to something better - void FrontToOutput() - { - if (ActiveResponseQueue.isEmpty() || CurrentText == ActiveResponseQueue[0]) - return; - - CurrentText = ActiveResponseQueue[0]; - ResetTalkVars(); - } - - void ResetTalkVars() - { - FinishedWriting = false; - TextRenderLength = 0; - WriteSpeed = 1; - CurrentRenderOutput = ""; - } - - void SetPreferedFont(string name) - { - PreferedFont = name; - } - - const string getName() - { - return CharacterName; - } - - void LoadTextConfig(string configName) - { - ConfigFile cf = ConfigFile(CFileMatcher(configName).getFirst()); - if (cf is null) - { - error("AttachedTextConfig " + configName + " is null (attached to character " + CharacterName + ")"); - return; - } - - // Optional - if (cf.exists("main")) - { - string main = cf.read_string("main"); - - AddResponse("main", main); - AddToResponseQueue("main"); - } - - // Optional - if (cf.exists("keys")) - { - // Temp work around until cfg has a get all keys func (would be named keys, but its an illegal name >:( - // Might crash here on empty box - string[] configKeys = cf.read_string("keys").split(';'); - - // Todo -> error if not found - for (int a = 0; a < configKeys.length; a++) - { - string text = cf.read_string(configKeys[a]); - if (text != "") - AddResponse(configKeys[a], text); - } - } - } - - // Temp bind with buttons - void ButtonPress() - { - if (!CurrentlyInteracting) - { - ResetTalkVars(); - CurrentlyInteracting = true; - } - } - - void Update() - { - CBlob@ blob = getLocalPlayerBlob(); - if (blob is null || !CurrentlyInteracting) - return; - - - LockMovement(blob); - bool spacebarPressed = ClientInputs(); - - if (spacebarPressed) - { - // Speed up writing - if (!FinishedWriting) - { - while(!FinishedWriting) - UpdateText(true); - } - else if (LoadNextInQueue()) - { - UpdateText(); - } - else - { - // User stops talking, gui closes - CurrentlyInteracting = false; - } - } - else - { - if (!FinishedWriting && getGameTime() % WriteSpeed == 0) - UpdateText(); - } - } - - // TODO: Clean up, its pretty ugly and prone to breaking (sorry) - void UpdateText(bool skip = false) - { - string chars = CurrentText.substr(TextRenderLength, 1); - - // Colour tokens - if (chars == '$') - { - for (int a = TextRenderLength + 1; a < CurrentText.length; a++) - { - string currentChar = CurrentText.substr(a, 1); - chars += currentChar; - if (currentChar == "$") - { - string temp = CurrentText.substr(a + 1, 1); - if (!isSpecialChar(temp)) - chars += temp; - - break; - } - } - } - else if (chars == '{') // Emote/Custom text logic - { - string insides = ""; - - for (int a = TextRenderLength + 1; a < CurrentText.length; a++) - { - string currentChar = CurrentText.substr(a, 1); - - if (currentChar == "}") - { - // Add in the next char so adding a token doesnt waste a text update - string temp = CurrentText.substr(a + 1, 1); - if (isSpecialChar(temp)) - chars = ""; - else - chars = temp; - - break; - } - - insides += currentChar; - } - - string action = insides.substr(0, 2); - string content = insides.substr(2, insides.length); - - // Emote (TODO: Move to BlobHandler) - if (action == "E_") - { - if (OwnerBlob is null) - warn("Dont call E_ with none blobs: " + CharacterName); - else - set_emote(OwnerBlob, Emotes::names.find(content)); - } - else if (action == "S_") // Write speed - { - WriteSpeed = parseInt(content); - chars = ""; - } - else if (action == "R_") // Add a new response to the queue - { - AddToResponseQueue(content); - } - else if (action == "F_") // Execute a function (TODO: change funcdef for non blobs) - { - CallbackButtonFunc@ func = getFunction(content); - if (func is null) - warn("Function not found " + content); - else - func(OwnerBlob, getLocalPlayerBlob()); // TODO -> Pass who called it, not just local player - } - - TextRenderLength += 2 + action.length + content.length; - } - else if (chars != ' ' && !skip) // TODO -> Set custom audio and sort out what we are doing with audio - { - Sound::Play("Archer_blip" + (XORRandom(1) == 0 ? "_2" : "")); - } - - CurrentRenderOutput += chars; - TextRenderLength += chars.length; - - if (TextRenderLength == CurrentText.length) - FinishedWriting = true; - } - - // TEMP, this was a gay temp work around - bool isSpecialChar(string input) - { - return (input == "{" || input == "}" || input == "$"); - } - - void LockMovement(CBlob@ blob) - { - blob.DisableKeys(KEYS_TO_TAKE); - blob.setVelocity(Vec2f( - 0.0f, - blob.getVelocity().y - )); - } - - // Note: Space bar wont active bombs - bool ClientInputs() - { - CControls@ controls = getControls(); - return controls.isKeyJustPressed(controls.getActionKeyKey(AK_ACTION3)); - } - - - void RenderBox() - { - Vec2f topLeft(0,0); - - // Character pane in pixels - const Vec2f pane = Vec2f(108, 100); - - // Text box background - // Todo -> update screenwidth every tick - const int rectangleWidth = getDriver().getScreenWidth(); - - // Bottom right - Vec2f botRight = Vec2f(topLeft.x + pane.x, topLeft.y + pane.y + 8); - - // Pane to the left - GUI::DrawFramedPane(topLeft, Vec2f(botRight.x, botRight.y)); - - // Move the rest slightly right since we got that pane - topLeft.x += pane.x; - - // Shadowed box that sits behind the text - GUI::DrawRectangle(topLeft, Vec2f(rectangleWidth, botRight.y), SColor(200,0,0,0)); - - // Render font (and make sure we set the font they want before hand) - GUI::SetFont(PreferedFont); - GUI::DrawText(CharacterName + " " + CurrentRenderOutput, Vec2f(topLeft.x + 25, topLeft.y + 10), - Vec2f(rectangleWidth - 25, botRight.y - 2), color_white, true, false, false); - - //GUI::DrawIcon("GUI/Keys.png", 8, Vec2f(24, 16), Vec2f(rectangleWidth - 25, botRight.y), 1.0f, color_white); - } -} - - -// Chat box used for global chat -// Not in use yet, will finish later on -/*class GlobalCharacter : Character -{ - +////////////////////// +/// +/// CharacterCore +/// +/// This holds the core class to character talking. +/// Currently not stable, everything is subject to change. +/// +/// The class is a mixin, which means another class can inherit everything from it +/// This is useful in this case so we can write less code + + +#include "EmotesCommon" + +const u16 KEYS_TO_TAKE = key_left | key_right | key_up | key_down | key_action1 | key_action2 | key_action3; + +mixin class Character +{ + // String key, string value + dictionary ResponseMap = dictionary(); + + // Maybe you want this character to have a custom font + // - Set your own custom font, used before rendering text + string PreferedFont = "pixeled"; + + // Custom character name, added to the start of the text render + // - Note: Will get changed at some point + string CharacterName = ""; + + // How fast should we write by default + // - Note: text cfg's can change this with "{S_NUM}" + int WriteSpeed = 1; + + // Are we done writing text? + // - Used to know if text is done updating + bool FinishedWriting = false; + + // We are interacting with a player + // - Used to end talking to the character (gui goes bye) + bool CurrentlyInteracting = false; + + // CurrentRenderOutput Total length including special tokens that are not outputted + // - Used when updating text so we can grab the correct substr + int TextRenderLength = 0; + + // Text render queue, when one is over done, the next will be pushed + string[] ActiveResponseQueue; + // Text that is currently on the screen + string CurrentRenderOutput = ""; + // The whole text that is being written to ^ + string CurrentText = ""; + + void SetName(string name) + { + CharacterName = name; + } + + void AddResponse(string eventName, string text) + { + ResponseMap.set(eventName, getTranslatedString(text)); + } + + // Both getResponses do the same thing, but give the string back in different ways + string getResponse(string eventName) + { + string text = ""; + ResponseMap.get(eventName, text); + return text; + } + + void GetResponse(string eventName, string &out text) + { + ResponseMap.get(eventName, text); + } + + void AddToResponseQueue(string eventName) + { + string response = getResponse(eventName); + if (response == "") + return; + + ActiveResponseQueue.push_back(response); + FrontToOutput(); + } + + void ClearResponseQueue() + { + ActiveResponseQueue.clear(); + } + + bool LoadNextInQueue() + { + if (ActiveResponseQueue.length < 2) + return false; + + RemoveFrontOfQueue(); + FrontToOutput(); + + return true; + } + + void RemoveFrontOfQueue() + { + if (ActiveResponseQueue.isEmpty()) + return; + + ActiveResponseQueue.erase(0); + } + + // Todo: rename to something better + void FrontToOutput() + { + if (ActiveResponseQueue.isEmpty() || CurrentText == ActiveResponseQueue[0]) + return; + + CurrentText = ActiveResponseQueue[0]; + ResetTalkVars(); + } + + void ResetTalkVars() + { + FinishedWriting = false; + TextRenderLength = 0; + WriteSpeed = 1; + CurrentRenderOutput = ""; + } + + void SetPreferedFont(string name) + { + PreferedFont = name; + } + + const string getName() + { + return CharacterName; + } + + void LoadTextConfig(string configName) + { + ConfigFile cf = ConfigFile(CFileMatcher(configName).getFirst()); + if (cf is null) + { + error("AttachedTextConfig " + configName + " is null (attached to character " + CharacterName + ")"); + return; + } + + // Optional + if (cf.exists("start")) + { + string sentence = cf.read_string("start"); + + AddResponse("start", sentence); + AddToResponseQueue("start"); + } + + // Optional + if (cf.exists("keys")) + { + // Temp work around until cfg has a get all keys func (would be named keys, but its an illegal name >:( + // Might crash here on empty box + string[] configKeys = cf.read_string("keys").split(';'); + + // Todo -> error if not found + for (int a = 0; a < configKeys.length; a++) + { + string text = cf.read_string(configKeys[a]); + if (text != "") + AddResponse(configKeys[a], text); + } + } + } + + // Temp bind with buttons + void ButtonPress() + { + if (!CurrentlyInteracting) + { + ResetTalkVars(); + CurrentlyInteracting = true; + } + } + + void Update() + { + CBlob@ blob = getLocalPlayerBlob(); + if (blob is null || !CurrentlyInteracting) + return; + + + LockMovement(blob); + bool spacebarPressed = ClientInputs(); + + if (spacebarPressed) + { + // Speed up writing + if (!FinishedWriting) + { + while(!FinishedWriting) + UpdateText(true); + } + else if (LoadNextInQueue()) + { + UpdateText(); + } + else + { + // User stops talking, gui closes + CurrentlyInteracting = false; + } + } + else + { + if (!FinishedWriting && getGameTime() % WriteSpeed == 0) + UpdateText(); + } + } + + // TODO: Clean up, its pretty ugly and prone to breaking (sorry) + void UpdateText(bool skip = false) + { + string chars = CurrentText.substr(TextRenderLength, 1); + + // Colour tokens + if (chars == '$') + { + for (int a = TextRenderLength + 1; a < CurrentText.length; a++) + { + string currentChar = CurrentText.substr(a, 1); + chars += currentChar; + if (currentChar == "$") + { + string temp = CurrentText.substr(a + 1, 1); + if (!isSpecialChar(temp)) + chars += temp; + + break; + } + } + } + else if (chars == '{') // Emote/Custom text logic + { + string insides = ""; + + for (int a = TextRenderLength + 1; a < CurrentText.length; a++) + { + string currentChar = CurrentText.substr(a, 1); + + if (currentChar == "}") + { + // Add in the next char so adding a token doesnt waste a text update + string temp = CurrentText.substr(a + 1, 1); + if (isSpecialChar(temp)) + chars = ""; + else + chars = temp; + + break; + } + + insides += currentChar; + } + + string action = insides.substr(0, 2); + string content = insides.substr(2, insides.length); + + // Emote (TODO: Move to BlobHandler) + if (action == "E_") + { + if (OwnerBlob is null) + warn("Dont call E_ with none blobs: " + CharacterName); + else + set_emote(OwnerBlob, Emotes::names.find(content)); + } + else if (action == "S_") // Write speed + { + WriteSpeed = parseInt(content); + chars = ""; + } + else if (action == "R_") // Add a new response to the queue + { + AddToResponseQueue(content); + } + else if (action == "F_") // Execute a function (TODO: change funcdef for non blobs) + { + CallbackButtonFunc@ func = getFunction(content); + if (func is null) + warn("Function not found " + content); + else + func(OwnerBlob, getLocalPlayerBlob()); // TODO -> Pass who called it, not just local player + } + + TextRenderLength += 2 + action.length + content.length; + } + else if (chars != ' ' && !skip) // TODO -> Set custom audio and sort out what we are doing with audio + { + Sound::Play("Archer_blip" + (XORRandom(1) == 0 ? "_2" : "")); + } + + CurrentRenderOutput += chars; + TextRenderLength += chars.length; + + if (TextRenderLength == CurrentText.length) + FinishedWriting = true; + } + + // TEMP, this was a gay temp work around + bool isSpecialChar(string input) + { + return (input == "{" || input == "}" || input == "$"); + } + + void LockMovement(CBlob@ blob) + { + blob.DisableKeys(KEYS_TO_TAKE); + blob.setVelocity(Vec2f( + 0.0f, + blob.getVelocity().y + )); + } + + // Note: Space bar wont active bombs + bool ClientInputs() + { + CControls@ controls = getControls(); + return controls.isKeyJustPressed(controls.getActionKeyKey(AK_ACTION3)); + } + + + void RenderBox() + { + Vec2f topLeft(0,0); + + // Character pane in pixels + const Vec2f pane = Vec2f(108, 100); + + // Text box background + // Todo -> update screenwidth every tick + const int rectangleWidth = getDriver().getScreenWidth(); + + // Bottom right + Vec2f botRight = Vec2f(topLeft.x + pane.x, topLeft.y + pane.y + 8); + + // Pane to the left + GUI::DrawFramedPane(topLeft, Vec2f(botRight.x, botRight.y)); + + // Move the rest slightly right since we got that pane + topLeft.x += pane.x; + + // Shadowed box that sits behind the text + GUI::DrawRectangle(topLeft, Vec2f(rectangleWidth, botRight.y), SColor(200,0,0,0)); + + // Render font (and make sure we set the font they want before hand) + GUI::SetFont(PreferedFont); + GUI::DrawText(CharacterName + " " + CurrentRenderOutput, Vec2f(topLeft.x + 25, topLeft.y + 10), + Vec2f(rectangleWidth - 25, botRight.y - 2), color_white, true, false, false); + + //GUI::DrawIcon("GUI/Keys.png", 8, Vec2f(24, 16), Vec2f(rectangleWidth - 25, botRight.y), 1.0f, color_white); + } +} + + +// Chat box used for global chat +// Not in use yet, will finish later on +/*class GlobalCharacter : Character +{ + }*/ \ No newline at end of file diff --git a/CoreScripts/Character/Configs/Kevin.cfg b/CoreScripts/Character/Configs/Kevin.cfg index 3127a96..cfc47f7 100644 --- a/CoreScripts/Character/Configs/Kevin.cfg +++ b/CoreScripts/Character/Configs/Kevin.cfg @@ -1,5 +1,5 @@ # First response, is not required -main = Now we{S_15}...{S_1}{E_knight} Fight!{S_30} +start = Now we{S_15}...{S_1}{E_knight} Fight!{S_30} {S_1}Or we can just talk{S_7}.....{S_1} I guess.. # Keys, list every other reponse in the config file (add in ; in between each key) diff --git a/CoreScripts/Character/Configs/Soren.cfg b/CoreScripts/Character/Configs/Soren.cfg index 9c64147..6376cdb 100644 --- a/CoreScripts/Character/Configs/Soren.cfg +++ b/CoreScripts/Character/Configs/Soren.cfg @@ -1,4 +1,4 @@ -main = $green$ *bush noises* {R_help} +start = $green$ *bush noises* {R_help} help = $green${F_self combust}{S_30}{S_5}*please help me*{E_frown} # Keys, list every other reponse in the config file (add in ; in between each key) keys = help diff --git a/CoreScripts/Character/InteractableCharacter.as b/CoreScripts/Character/InteractableCharacter.as index 2412be2..558c0fa 100644 --- a/CoreScripts/Character/InteractableCharacter.as +++ b/CoreScripts/Character/InteractableCharacter.as @@ -1,50 +1,50 @@ -////////////////////// -/// -/// InteractableCharacter -/// -/// This is added to any new blob when used with MapsCore addCharacterToBlob -/// Code in this is subject to change, buttons were used just as a quick and simple way to test the code - -// TODO -> Create Token - -#include "BlobCharacter" - -void onInit(CBlob@ this) -{ - if (getCharacter(this) is null) - { - error("Blob " + this.getName() + " has InteractableCharacter.as with no character!"); - this.RemoveScript("InteractableCharacter"); - return; - } -} - -void GetButtonsFor(CBlob@ this, CBlob@ caller) -{ - // Unsure if this can even go null - BlobCharacter@ char = getCharacter(this); - - if (caller is null || this.hasTag("dead") || char is null || char.CurrentlyInteracting) - return; - - CButton@ button = caller.CreateGenericButton("$trade$", Vec2f_zero, this, TryingToTalk, "Test"); -} - -void TryingToTalk(CBlob@ this, CBlob@ caller) -{ - BlobCharacter@ char = getCharacter(this); - char.ButtonPress(); -} - - - -void onHealthChange(CBlob@ this, f32 oldHealth) -{ - // Work around to 'Invalid networkid' for trying to tell CRules to remove our character - if (this.hasTag("dead")) - { - CBitStream cbs = CBitStream(); - cbs.write_u16(this.getNetworkID()); - getRules().SendCommand(getRules().getCommandID("character_unbound"), cbs); - } +////////////////////// +/// +/// InteractableCharacter +/// +/// This is added to any new blob when used with MapsCore addCharacterToBlob +/// Code in this is subject to change, buttons were used just as a quick and simple way to test the code + +// TODO -> Create Token + +#include "BlobCharacter" + +void onInit(CBlob@ this) +{ + if (getCharacter(this) is null) + { + error("Blob " + this.getName() + " has InteractableCharacter.as with no character!"); + this.RemoveScript("InteractableCharacter"); + return; + } +} + +void GetButtonsFor(CBlob@ this, CBlob@ caller) +{ + // Unsure if this can even go null + BlobCharacter@ char = getCharacter(this); + + if (caller is null || this.hasTag("dead") || char is null || char.CurrentlyInteracting) + return; + + CButton@ button = caller.CreateGenericButton("$trade$", Vec2f_zero, this, TryingToTalk, "Test"); +} + +void TryingToTalk(CBlob@ this, CBlob@ caller) +{ + BlobCharacter@ char = getCharacter(this); + char.ButtonPress(); +} + + + +void onHealthChange(CBlob@ this, f32 oldHealth) +{ + // Work around to 'Invalid networkid' for trying to tell CRules to remove our character + if (this.hasTag("dead")) + { + CBitStream cbs = CBitStream(); + cbs.write_u16(this.getNetworkID()); + getRules().SendCommand(getRules().getCommandID("character_unbound"), cbs); + } } \ No newline at end of file diff --git a/CoreScripts/Events/EventCore.as b/CoreScripts/Events/EventCore.as index 1d88b88..614954c 100644 --- a/CoreScripts/Events/EventCore.as +++ b/CoreScripts/Events/EventCore.as @@ -1,69 +1,69 @@ -/////////////////////////////////////////////////////////// -//// -//// Event Core -//// -//// This will contain any important core classes -//// for making any event for kag levels -//// -//// Other .as files will use this to make their own -//// Event -//// -/////////////////////////////////////////////////////////// - -// Hook a func with CBlob -funcdef void EventFunc(CBlob@ caller); - -// A pre callback check before we call whats above (e.g. do we meet said conditions) -funcdef bool PreEventCheck(CBlob@ caller); - -// A class used so we can easily make custom wrappers around it -mixin class Event -{ - // Callback to a func for out event - private EventFunc@ Callback; - // A callback to see if we should run out event (not required) - private PreEventCheck@ PreCheck; - // Should we delete this event after its called - bool DestroyAfterCall = true; - - // Constructors for the event mixin so we can quickly call this - void Event(EventFunc@ mainEvent, PreEventCheck@ checkEvent = null, bool removeAfterUse = true) - { - @Callback = mainEvent; - @PreCheck = checkEvent; - DestroyAfterCall = removeAfterUse; - } - - // Should we call, if so call main event - bool CheckAndEvent(CBlob@ caller) - { - if (PreCheck !is null) - { - if (PreCheck(caller)) - return CallEvent(caller); - } - else - { - return CallEvent(caller); - } - - return false; - } - - // Can we call it - bool canWeCallEvent(CBlob@ caller) - { - return (PreCheck !is null ? PreCheck(caller) : false); - } - - // Call the event, we dont care about pre check! - bool CallEvent(CBlob@ caller) - { - Callback(caller); - - if (DestroyAfterCall) - return true; - - return false; - } -}; +/////////////////////////////////////////////////////////// +//// +//// Event Core +//// +//// This will contain any important core classes +//// for making any event for kag levels +//// +//// Other .as files will use this to make their own +//// Event +//// +/////////////////////////////////////////////////////////// + +// Hook a func with CBlob +funcdef void EventFunc(CBlob@ caller); + +// A pre callback check before we call whats above (e.g. do we meet said conditions) +funcdef bool PreEventCheck(CBlob@ caller); + +// A class used so we can easily make custom wrappers around it +mixin class Event +{ + // Callback to a func for out event + private EventFunc@ Callback; + // A callback to see if we should run out event (not required) + private PreEventCheck@ PreCheck; + // Should we delete this event after its called + bool DestroyAfterCall = true; + + // Constructors for the event mixin so we can quickly call this + void Event(EventFunc@ mainEvent, PreEventCheck@ checkEvent = null, bool removeAfterUse = true) + { + @Callback = mainEvent; + @PreCheck = checkEvent; + DestroyAfterCall = removeAfterUse; + } + + // Should we call, if so call main event + bool CheckAndEvent(CBlob@ caller) + { + if (PreCheck !is null) + { + if (PreCheck(caller)) + return CallEvent(caller); + } + else + { + return CallEvent(caller); + } + + return false; + } + + // Can we call it + bool canWeCallEvent(CBlob@ caller) + { + return (PreCheck !is null ? PreCheck(caller) : false); + } + + // Call the event, we dont care about pre check! + bool CallEvent(CBlob@ caller) + { + Callback(caller); + + if (DestroyAfterCall) + return true; + + return false; + } +}; diff --git a/CoreScripts/Events/EventSector.as b/CoreScripts/Events/EventSector.as index 9bd597b..cce1abd 100644 --- a/CoreScripts/Events/EventSector.as +++ b/CoreScripts/Events/EventSector.as @@ -1,153 +1,153 @@ - -////////////////////// -/// -/// EventSectors -/// -/// This script will allow you to set up sectors and do events -/// Check Test.as for use examples - -#include "EventCore" - -class SectorEvent : Event -{ - // Map sector, we don't want external sources messing with this - private CMap::Sector@ EventSector; - - // An id is needed, we cant use Sector ownerid unless you - // want sectors to go when a blob despawns randomly - u16 Id = 0; - - SectorEvent(EventFunc@ mainEvent, PreEventCheck@ checkEvent, Vec2f topLeft, Vec2f botRight, bool removeAfterUse = true) - { - @EventSector = getMap().server_AddSector(topLeft, botRight, Id + ''); - Event(mainEvent, checkEvent, removeAfterUse); - } - - SectorEvent(EventFunc@ mainEvent, Vec2f topLeft, Vec2f botRight, bool removeAfterUse = true) - { - this = SectorEvent(mainEvent, null, topLeft, botRight, removeAfterUse); - } - - void SetNewSector(CMap::Sector@ newSector, bool removeOld = true) - { - if (removeOld && EventSector !is null) - RemoveSector(); - - @EventSector = newSector; - } - - const CMap::Sector@ getSector() - { - return EventSector; - } - - void ChangeId(const u16 newId) - { - EventSector.name = newId+''; - Id = newId; - } - - void RemoveSector() - { - getMap().RemoveSectorsAtPosition(EventSector.center, EventSector.name); - } -}; - -class SectorHandler -{ - array EventList; - CMap@ map; - - SectorHandler() - { - @map = getMap(); - } - - void AddNewEvent(SectorEvent@ newEvent) - { - if (newEvent !is null) - { - newEvent.ChangeId(EventList.length); - EventList.push_back(newEvent); - } - } - - void PushBack(SectorEvent@ newEvent) - { - AddNewEvent(newEvent); - } - - void Clear() - { - EventList.clear(); - } - - // Make sure you call RepairIndex's after - void RemoveNoRepair(int index) - { - if (index < EventList.length) - { - EventList[index].RemoveSector(); - EventList.erase(index); - } - } - - void Remove(int index) - { - if (index < EventList.length) - { - EventList[index].RemoveSector(); - EventList.erase(index); - - RepairIndexIds(); - } - } - - // Stop's a common crash - void Reverse(int newSize) - { - if (EventList.length > 0) - { - EventList.reverse(); - RepairIndexIds(); - } - } - - void RepairIndexIds() - { - for (u16 a = 0; a < EventList.length; a++) - { - EventList[a].ChangeId(a); - } - } - - void OnTick(CBlob@ blob) - { - CMap::Sector@[] sectors; - - // Returns true if sectors are found - if (map.getSectorsAtPosition(blob.getPosition(), @sectors)) - { - for(int a = 0; a < sectors.length; a++) - { - u16 id = parseInt(sectors[a].name); - SectorEvent@ event = EventList[id]; - - // Returns true if we should destroy after calling - if (event.CheckAndEvent(blob)) - Remove(id); - } - } - } - - void Destroy() - { - for (int a = 0; a < EventList.length; a++) - { - if (EventList[a] !is null) - { - EventList[a].RemoveSector(); - } - } - } + +////////////////////// +/// +/// EventSectors +/// +/// This script will allow you to set up sectors and do events +/// Check Test.as for use examples + +#include "EventCore" + +class SectorEvent : Event +{ + // Map sector, we don't want external sources messing with this + private CMap::Sector@ EventSector; + + // An id is needed, we cant use Sector ownerid unless you + // want sectors to go when a blob despawns randomly + u16 Id = 0; + + SectorEvent(EventFunc@ mainEvent, PreEventCheck@ checkEvent, Vec2f topLeft, Vec2f botRight, bool removeAfterUse = true) + { + @EventSector = getMap().server_AddSector(topLeft, botRight, Id + ''); + Event(mainEvent, checkEvent, removeAfterUse); + } + + SectorEvent(EventFunc@ mainEvent, Vec2f topLeft, Vec2f botRight, bool removeAfterUse = true) + { + this = SectorEvent(mainEvent, null, topLeft, botRight, removeAfterUse); + } + + void SetNewSector(CMap::Sector@ newSector, bool removeOld = true) + { + if (removeOld && EventSector !is null) + RemoveSector(); + + @EventSector = newSector; + } + + const CMap::Sector@ getSector() + { + return EventSector; + } + + void ChangeId(const u16 newId) + { + EventSector.name = newId+''; + Id = newId; + } + + void RemoveSector() + { + getMap().RemoveSectorsAtPosition(EventSector.center, EventSector.name); + } +}; + +class SectorHandler +{ + array EventList; + CMap@ map; + + SectorHandler() + { + @map = getMap(); + } + + void AddNewEvent(SectorEvent@ newEvent) + { + if (newEvent !is null) + { + newEvent.ChangeId(EventList.length); + EventList.push_back(newEvent); + } + } + + void PushBack(SectorEvent@ newEvent) + { + AddNewEvent(newEvent); + } + + void Clear() + { + EventList.clear(); + } + + // Make sure you call RepairIndex's after + void RemoveNoRepair(int index) + { + if (index < EventList.length) + { + EventList[index].RemoveSector(); + EventList.erase(index); + } + } + + void Remove(int index) + { + if (index < EventList.length) + { + EventList[index].RemoveSector(); + EventList.erase(index); + + RepairIndexIds(); + } + } + + // Stop's a common crash + void Reverse(int newSize) + { + if (EventList.length > 0) + { + EventList.reverse(); + RepairIndexIds(); + } + } + + void RepairIndexIds() + { + for (u16 a = 0; a < EventList.length; a++) + { + EventList[a].ChangeId(a); + } + } + + void OnTick(CBlob@ blob) + { + CMap::Sector@[] sectors; + + // Returns true if sectors are found + if (map.getSectorsAtPosition(blob.getPosition(), @sectors)) + { + for(int a = 0; a < sectors.length; a++) + { + u16 id = parseInt(sectors[a].name); + SectorEvent@ event = EventList[id]; + + // Returns true if we should destroy after calling + if (event.CheckAndEvent(blob)) + Remove(id); + } + } + } + + void Destroy() + { + for (int a = 0; a < EventList.length; a++) + { + if (EventList[a] !is null) + { + EventList[a].RemoveSector(); + } + } + } }; \ No newline at end of file diff --git a/CoreScripts/Rules/CharacterHandler.as b/CoreScripts/Rules/CharacterHandler.as index a93c892..65fbbc6 100644 --- a/CoreScripts/Rules/CharacterHandler.as +++ b/CoreScripts/Rules/CharacterHandler.as @@ -1,109 +1,114 @@ -////////////////////// -/// -/// CharacterHandler -/// -/// This script is added into gamemode.cfg -/// It handles rendering, ticking and clearing BlobCharacterHandler -/// This may change later on, as I'd like this to render all other 'Character' type classes (if we ever do that) - -#include "BlobCharacter" -#include "RunnerTextures" - -BlobCharacterHandler@ Handler; - -// In localhost, this executes before CMap onInit does -void onInit(CRules@ this) -{ - // This will be called when ever we have set a character - // The blob network ID will need to be sent as well. - this.addCommandID("character_bound"); - // This will be called when a blob dies - // This is required unless you want the game to crash - this.addCommandID("character_unbound"); - - onRestart(this); - - // Might get used if we want to use render:: in character rendering anywhere - //id = Render::addScript(Render::layer_posthud, "CharacterHandler.as", "NewRender", 10.0f); -} - -void onRestart(CRules@ this) -{ - if (Handler !is null) - Handler.Clear(); - - @Handler = BlobCharacterHandler(); -} - -void onReload(CRules@ this) -{ - if (Handler !is null) - Handler.Clear(); - - @Handler = BlobCharacterHandler(); - - // Only for reloads - CBlob@[] blobs; - getBlobs(@blobs); - - for (int a = 0; a < blobs.length; a++) - { - CBlob@ blob = blobs[a]; - if (blob is null) - continue; - - BlobCharacter@ char = getCharacter(blob); - - if (char is null) - continue; - - Handler.AddCharacter(char); - } - // End -} - -void onTick(CRules@ this) -{ - if (Handler !is null) - Handler.onTick(); -} - -void onCommand(CRules@ this, u8 cmd, CBitStream@ params) -{ - - if (Handler is null) - return; - - if (cmd == this.getCommandID("character_bound")) - { - u16 networkId = params.read_u16(); - CBlob@ blob = getBlobByNetworkID(networkId); - - if (blob is null) - { - error("Invalid networkid character_bound : " + networkId); - return; - } - - Handler.AddCharacter(blob); - } - else if (cmd == this.getCommandID("character_unbound")) - { - u16 networkId = params.read_u16(); - CBlob@ blob = getBlobByNetworkID(networkId); - - if (blob is null) - { - error("Invalid networkid character_bound : " + networkId); - return; - } - - Handler.RemoveCharacter(blob); - } -} - -void onRender(CRules@ this) -{ - if (Handler !is null) - Handler.onRender(); -} \ No newline at end of file +////////////////////// +/// +/// CharacterHandler +/// +/// This script is added into gamemode.cfg +/// It handles rendering, ticking and clearing BlobCharacterHandler +/// This may change later on, as I'd like this to render all other 'Character' type classes (if we ever do that) + +#include "BlobCharacter" +#include "RunnerTextures" + +BlobCharacterHandler@ Handler; + +// In localhost, this executes before CMap onInit does +void onInit(CRules@ this) +{ + // This will be called when ever we have set a character + // The blob network ID will need to be sent as well. + this.addCommandID("character_bound"); + // This will be called when a blob dies + // This is required unless you want the game to crash + this.addCommandID("character_unbound"); + + onRestart(this); + + // Might get used if we want to use render:: in character rendering anywhere + //id = Render::addScript(Render::layer_posthud, "CharacterHandler.as", "NewRender", 10.0f); +} + +void onRestart(CRules@ this) +{ + if (Handler !is null) + Handler.Clear(); + + @Handler = BlobCharacterHandler(); +} + +void onReload(CRules@ this) +{ + if (Handler !is null) + Handler.Clear(); + + @Handler = BlobCharacterHandler(); + + // Only for reloads + CBlob@[] blobs; + getBlobs(@blobs); + + for (int a = 0; a < blobs.length; a++) + { + CBlob@ blob = blobs[a]; + if (blob is null) + continue; + + BlobCharacter@ char = getCharacter(blob); + + if (char is null) + continue; + + Handler.AddCharacter(char); + } + // End +} + +void onTick(CRules@ this) +{ + if (Handler !is null) + Handler.onTick(); +} + +void onCommand(CRules@ this, u8 cmd, CBitStream@ params) +{ + + if (Handler is null) + return; + + if (cmd == this.getCommandID("character_bound")) + { + u16 networkId = params.read_u16(); + CBlob@ blob = getBlobByNetworkID(networkId); + + if (blob is null) + { + error("Invalid networkid character_bound : " + networkId); + return; + } + + Handler.AddCharacter(blob); + } + else if (cmd == this.getCommandID("character_unbound")) + { + u16 networkId = params.read_u16(); + CBlob@ blob = getBlobByNetworkID(networkId); + + if (blob is null) + { + error("Invalid networkid character_bound : " + networkId); + return; + } + + Handler.RemoveCharacter(blob); + } +} + +void onRender(CRules@ this) +{ + if (Handler !is null) + Handler.onRender(); +} + + + + +//void StartDebug() \ No newline at end of file diff --git a/Maps/CommonScripts/MapsCore.as b/Maps/CommonScripts/MapsCore.as index 17d5f7e..d0f2205 100644 --- a/Maps/CommonScripts/MapsCore.as +++ b/Maps/CommonScripts/MapsCore.as @@ -1,147 +1,147 @@ -////////////////////// -/// -/// MapsCore -/// -/// Used so there's less duplicate code with adding a map level - -#include "BlobCharacter" -#include "RunnerHead" - -// Add in spawns based on a blob -// Some maps might want you to spawn at a tent -// Some might want you to spawn at a shop, idk -// -// Returns true if spawning was done correctly -bool AddSpawns(CMap@ map, string markerName, string blobToSpawn, int teamNum = 0) -{ - Vec2f[] spawns; - if (map.getMarkers(markerName, spawns)) - { - for (int a = 0; a < spawns.length; a++) - { - server_CreateBlob(blobToSpawn, 0, spawns[a]); - } - - return true; - } - - return false; -} - -// Same as above, but we remove all scripts attached to them -// This prevents us from using it -bool AddSpawnsCosmeticOnly(CMap@ map, string markerName, string blobToSpawn, int teamNum = 0) -{ - Vec2f[] spawns; - if (map.getMarkers(markerName, spawns)) - { - for (int a = 0; a < spawns.length; a++) - { - CBlob@ blob = server_CreateBlob(blobToSpawn, 0, spawns[a]); - if (blob is null) - continue; - - // TODO-> Engine side need a way to get all scripts by name! - } - - return true; - } - - return false; -} - - - -/*CBlob@ SpawnInCharacter(string blobName, int team, Vec2f pos, string characterName, bool onInit = true, string customBody = "") -{ - CBlob@ blob = null; - - // Offer them an option to auto init or not - // In case they want to set their own settings - if (onInit) - { - @blob = server_CreateBlob(blobName, team, pos); - } - else - { - @blob = server_CreateBlobNoInit(blobName); - blob.setPosition(pos); - blob.server_setTeamNum(team); - } - - if (blob is null) { - error("SpawnInCharacter creating a blob has failed!"); - return null; - } - - if (customBody != "") - blob.set_string("custom_body", customBody); - - blob.AddScript("InteractableCharacter"); - - // Set character data - BlobCharacter@ character = BlobCharacter(blob, characterName); - character.PushToGlobalHandler(); - - return blob; -}*/ - -BlobCharacter@ addCharacterToBlob(CBlob@ blob, string &in characterName, string &in textFile) -{ - if (blob.hasScript("InteractableCharacter")) - { - error("Trying to add a script to a blob that already has InteractableCharacter.as"); - return null; - } - - blob.AddScript("InteractableCharacter"); - - BlobCharacter@ character = BlobCharacter(blob, characterName); - character.LoadTextConfig(textFile); - character.PushToGlobalHandler(); - - - if (!blob.hasScript("EmoteBubble.as")) - { - blob.AddScript("EmoteBubble.as"); - } - - return character; -} - - - -/// TODO: MOVE TO A NEW FILE - - -// Basic 0 to 255 (70 heads) -// Flags 256 to 511 (78 heads) -// Fantasy 512 to 767 (18 heads) -// Community 768 to 1023 (60 heads) -// 30 unique heads per pack - -namespace Heads -{ - const int[] KNIGHT_WITH_HELMS = { - 46, - 47, - 48, - 50, - 53, - 54, - 55, - 815, - 819, - 823, - 824, - 825, - 826 - }; -} - -// Todo, maybe include this with a custom CreateBlob & addCharacter func -void SetRandomKnightHelm(CBlob@ blob) -{ - blob.setHeadNum(Heads::KNIGHT_WITH_HELMS[XORRandom(Heads::KNIGHT_WITH_HELMS.length)]); - LoadHead(blob.getSprite(), blob.getHeadNum()); -} +////////////////////// +/// +/// MapsCore +/// +/// Used so there's less duplicate code with adding a map level + +#include "BlobCharacter" +#include "RunnerHead" + +// Add in spawns based on a blob +// Some maps might want you to spawn at a tent +// Some might want you to spawn at a shop, idk +// +// Returns true if spawning was done correctly +bool AddSpawns(CMap@ map, string markerName, string blobToSpawn, int teamNum = 0) +{ + Vec2f[] spawns; + if (map.getMarkers(markerName, spawns)) + { + for (int a = 0; a < spawns.length; a++) + { + server_CreateBlob(blobToSpawn, 0, spawns[a]); + } + + return true; + } + + return false; +} + +// Same as above, but we remove all scripts attached to them +// This prevents us from using it +bool AddSpawnsCosmeticOnly(CMap@ map, string markerName, string blobToSpawn, int teamNum = 0) +{ + Vec2f[] spawns; + if (map.getMarkers(markerName, spawns)) + { + for (int a = 0; a < spawns.length; a++) + { + CBlob@ blob = server_CreateBlob(blobToSpawn, 0, spawns[a]); + if (blob is null) + continue; + + // TODO-> Engine side need a way to get all scripts by name! + } + + return true; + } + + return false; +} + + + +/*CBlob@ SpawnInCharacter(string blobName, int team, Vec2f pos, string characterName, bool onInit = true, string customBody = "") +{ + CBlob@ blob = null; + + // Offer them an option to auto init or not + // In case they want to set their own settings + if (onInit) + { + @blob = server_CreateBlob(blobName, team, pos); + } + else + { + @blob = server_CreateBlobNoInit(blobName); + blob.setPosition(pos); + blob.server_setTeamNum(team); + } + + if (blob is null) { + error("SpawnInCharacter creating a blob has failed!"); + return null; + } + + if (customBody != "") + blob.set_string("custom_body", customBody); + + blob.AddScript("InteractableCharacter"); + + // Set character data + BlobCharacter@ character = BlobCharacter(blob, characterName); + character.PushToGlobalHandler(); + + return blob; +}*/ + +BlobCharacter@ addCharacterToBlob(CBlob@ blob, string &in characterName, string &in textFile) +{ + if (blob.hasScript("InteractableCharacter")) + { + error("Trying to add a script to a blob that already has InteractableCharacter.as"); + return null; + } + + blob.AddScript("InteractableCharacter"); + + BlobCharacter@ character = BlobCharacter(blob, characterName); + character.LoadTextConfig(textFile); + character.PushToGlobalHandler(); + + + if (!blob.hasScript("EmoteBubble.as")) + { + blob.AddScript("EmoteBubble.as"); + } + + return character; +} + + + +/// TODO: MOVE TO A NEW FILE + + +// Basic 0 to 255 (70 heads) +// Flags 256 to 511 (78 heads) +// Fantasy 512 to 767 (18 heads) +// Community 768 to 1023 (60 heads) +// 30 unique heads per pack + +namespace Heads +{ + const int[] KNIGHT_WITH_HELMS = { + 46, + 47, + 48, + 50, + 53, + 54, + 55, + 815, + 819, + 823, + 824, + 825, + 826 + }; +} + +// Todo, maybe include this with a custom CreateBlob & addCharacter func +void SetRandomKnightHelm(CBlob@ blob) +{ + blob.setHeadNum(Heads::KNIGHT_WITH_HELMS[XORRandom(Heads::KNIGHT_WITH_HELMS.length)]); + LoadHead(blob.getSprite(), blob.getHeadNum()); +} diff --git a/Maps/KnightShowcase/KnightShowcase.as b/Maps/KnightShowcase/KnightShowcase.as index d8f36d8..b0c4752 100644 --- a/Maps/KnightShowcase/KnightShowcase.as +++ b/Maps/KnightShowcase/KnightShowcase.as @@ -1,100 +1,100 @@ -////////////////////// -/// -/// KnightShowcase map -/// -/// This is a test level with blobs talking -/// Will clean when everything becomes more stable - -#include "MapsCore" -#include "FireCommon" - -void onInit(CMap@ this) -{ - string AveriaSerif = CFileMatcher("AveriaSerif-Bold.ttf").getFirst(); - GUI::LoadFont("AveriaSerif-Bold_22", AveriaSerif, 22, true); - onRestart(this); -} - -void onRulesRestart(CMap@ this, CRules@ rules) -{ - onRestart(this); -} - -CBlob@ blob = null; - -// NOT A HOOK -void onRestart(CMap@ this) -{ - if(!AddSpawns(this, "blue main spawn", "tent") && AddSpawns(this, "blue spawn", "tent")) - { - error("Could not find spawn markers to place!"); - } - - //SpawnInCharacter("knight", 1, Vec2f(538, 560), "generic knight main"); - //SpawnInCharacter("archer", 0, Vec2f(555, 560), "generic archer main"); - //SpawnInCharacter("builder", 3, Vec2f(575, 560), "generic builder main"); - - @blob = null; - TrySpawnBlob(); -} - -void onTick(CMap@ map) -{ - TrySpawnBlob(); - - if (blob is null) - return; - - if (getControls().isKeyPressed(KEY_KEY_Z)) - SetRandomKnightHelm(blob); -} - - -// TEMP -void TrySpawnBlob() -{ - if (blob is null) - { - CBlob@[] list; - getBlobs(@list); - for (int a = 0; a < list.length(); a++) - { - CBlob@ temp = list[a]; - if (temp is null || temp.getPlayer() !is null) - continue; - - if (temp.getName() == "knight" || temp.getName() == "bush") - temp.server_Die(); - } - - @blob = server_CreateBlob("knight", 0, Vec2f(538, 560)); - addCharacterToBlob(blob, "Kevin the tester", "Kevin.cfg"); - SetRandomKnightHelm(blob); - - @blob = server_CreateBlob("bush", 0, Vec2f(144, 579)); - BlobCharacter@ char = addCharacterToBlob(blob, "Soren the bush", "Soren.cfg"); - - char.AddFunction("self combust", Fireeee); - } -} - -// This is the blob with BlobCharacter, caller is our local player -// temp to soren bush -void Fireeee(CBlob@ this, CBlob@ caller) -{ - if (!this.hasScript("FireAnim.as")) - this.AddScript("FireAnim.as"); - - ParticleZombieLightning(this.getPosition()); - - this.Tag("burning"); - this.Sync("burning", true); - - // Force fire to show up, the reason for this is because fireanim doesnt tick all too often - CSpriteLayer@ fire = this.getSprite().getSpriteLayer("fire_animation_large"); - if (fire !is null) - { - fire.SetVisible(true); - fire.SetAnimation("smallfire"); - } +////////////////////// +/// +/// KnightShowcase map +/// +/// This is a test level with blobs talking +/// Will clean when everything becomes more stable + +#include "MapsCore" +#include "FireCommon" + +void onInit(CMap@ this) +{ + string AveriaSerif = CFileMatcher("AveriaSerif-Bold.ttf").getFirst(); + GUI::LoadFont("AveriaSerif-Bold_22", AveriaSerif, 22, true); + onRestart(this); +} + +void onRulesRestart(CMap@ this, CRules@ rules) +{ + onRestart(this); +} + +CBlob@ blob = null; + +// NOT A HOOK +void onRestart(CMap@ this) +{ + if(!AddSpawns(this, "blue main spawn", "tent") && AddSpawns(this, "blue spawn", "tent")) + { + error("Could not find spawn markers to place!"); + } + + //SpawnInCharacter("knight", 1, Vec2f(538, 560), "generic knight main"); + //SpawnInCharacter("archer", 0, Vec2f(555, 560), "generic archer main"); + //SpawnInCharacter("builder", 3, Vec2f(575, 560), "generic builder main"); + + @blob = null; + TrySpawnBlob(); +} + +void onTick(CMap@ map) +{ + TrySpawnBlob(); + + if (blob is null) + return; + + if (getControls().isKeyPressed(KEY_KEY_Z)) + SetRandomKnightHelm(blob); +} + + +// TEMP +void TrySpawnBlob() +{ + if (blob is null) + { + CBlob@[] list; + getBlobs(@list); + for (int a = 0; a < list.length(); a++) + { + CBlob@ temp = list[a]; + if (temp is null || temp.getPlayer() !is null) + continue; + + if (temp.getName() == "knight" || temp.getName() == "bush") + temp.server_Die(); + } + + @blob = server_CreateBlob("knight", 0, Vec2f(538, 560)); + addCharacterToBlob(blob, "Kevin the tester", "Kevin.cfg"); + SetRandomKnightHelm(blob); + + @blob = server_CreateBlob("bush", 0, Vec2f(144, 579)); + BlobCharacter@ char = addCharacterToBlob(blob, "Soren the bush", "Soren.cfg"); + + char.AddFunction("self combust", Fireeee); + } +} + +// This is the blob with BlobCharacter, caller is our local player +// temp to soren bush +void Fireeee(CBlob@ this, CBlob@ caller) +{ + if (!this.hasScript("FireAnim.as")) + this.AddScript("FireAnim.as"); + + ParticleZombieLightning(this.getPosition()); + + this.Tag("burning"); + this.Sync("burning", true); + + // Force fire to show up, the reason for this is because fireanim doesnt tick all too often + CSpriteLayer@ fire = this.getSprite().getSpriteLayer("fire_animation_large"); + if (fire !is null) + { + fire.SetVisible(true); + fire.SetAnimation("smallfire"); + } } \ No newline at end of file diff --git a/Maps/Test/Test.as b/Maps/Test/Test.as index 9bf14e8..94241e1 100644 --- a/Maps/Test/Test.as +++ b/Maps/Test/Test.as @@ -1,70 +1,70 @@ -////////////////////// -/// -/// TEST MAP -/// -/// This is a test with sector events. -/// This may break in the future - -#include "EventSector" - -SectorHandler@ handler; - -void onInit(CMap@ this) -{ - onRulesRestart(this, null); -} - -void onRulesRestart( CMap@ this, CRules@ rules ) -{ - this.RemoveAllSectors(); - - @handler = SectorHandler(); - - handler.AddNewEvent( - SectorEvent(HelloWorld, Vec2f(95, 419), Vec2f(184, 471), true) - ); - - handler.AddNewEvent( - SectorEvent(HelloWorld, Vec2f(260, 410), Vec2f(411, 469), false) - ); - - handler.AddNewEvent( - SectorEvent(HelloWorld, BombCheck, Vec2f(474, 410), Vec2f(617, 466), false) - ); -} - -void HelloWorld(CBlob@ caller) -{ - server_CreateBlob("chicken", -1, caller.getPosition()); -} - -bool BombCheck(CBlob@ caller) -{ - CBlob@ blob = caller.getAttachments().getAttachmentPointByName("PICKUP").getOccupied(); - - if (blob !is null && blob.getName() == "mat_bombs") - { - return true; - } - - return false; -} - -void onTick(CMap@ this) -{ - CBlob@ blob = getLocalPlayerBlob(); - - if (handler is null || blob is null) - return; - - handler.OnTick(blob); -} - -void onRender(CMap@ this) -{ - GUI::DrawText("One time use event", getDriver().getScreenPosFromWorldPos(Vec2f(115, 400)), SColor(255,255,255,255)); - - GUI::DrawText("Infinite use event", getDriver().getScreenPosFromWorldPos(Vec2f(300, 400)), SColor(255,255,255,255)); - - GUI::DrawText("Event with condition check", getDriver().getScreenPosFromWorldPos(Vec2f(520, 400)), SColor(255,255,255,255)); +////////////////////// +/// +/// TEST MAP +/// +/// This is a test with sector events. +/// This may break in the future + +#include "EventSector" + +SectorHandler@ handler; + +void onInit(CMap@ this) +{ + onRulesRestart(this, null); +} + +void onRulesRestart( CMap@ this, CRules@ rules ) +{ + this.RemoveAllSectors(); + + @handler = SectorHandler(); + + handler.AddNewEvent( + SectorEvent(HelloWorld, Vec2f(95, 419), Vec2f(184, 471), true) + ); + + handler.AddNewEvent( + SectorEvent(HelloWorld, Vec2f(260, 410), Vec2f(411, 469), false) + ); + + handler.AddNewEvent( + SectorEvent(HelloWorld, BombCheck, Vec2f(474, 410), Vec2f(617, 466), false) + ); +} + +void HelloWorld(CBlob@ caller) +{ + server_CreateBlob("chicken", -1, caller.getPosition()); +} + +bool BombCheck(CBlob@ caller) +{ + CBlob@ blob = caller.getAttachments().getAttachmentPointByName("PICKUP").getOccupied(); + + if (blob !is null && blob.getName() == "mat_bombs") + { + return true; + } + + return false; +} + +void onTick(CMap@ this) +{ + CBlob@ blob = getLocalPlayerBlob(); + + if (handler is null || blob is null) + return; + + handler.OnTick(blob); +} + +void onRender(CMap@ this) +{ + GUI::DrawText("One time use event", getDriver().getScreenPosFromWorldPos(Vec2f(115, 400)), SColor(255,255,255,255)); + + GUI::DrawText("Infinite use event", getDriver().getScreenPosFromWorldPos(Vec2f(300, 400)), SColor(255,255,255,255)); + + GUI::DrawText("Event with condition check", getDriver().getScreenPosFromWorldPos(Vec2f(520, 400)), SColor(255,255,255,255)); } \ No newline at end of file diff --git a/README.md b/README.md index bf678d1..f317eff 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# KAG Tutorial rewrite -In progress rewrite of KAG's tutorial. - -A lot of the code here is in development, so it will be a bit messy at first. - -Feel free to take a look and give it a try. There is not much right now aside from being able to interact with some test blobs. -Please don't use parts of this without asking for the time being. +# KAG Tutorial rewrite +In progress rewrite of KAG's tutorial. + +A lot of the code here is in development, so it will be a bit messy at first. + +Feel free to take a look and give it a try. There is not much right now aside from being able to interact with some test blobs. +Please don't use parts of this without asking for the time being. diff --git a/TutorialMain.as b/TutorialMain.as index 955d5e1..919ebf6 100644 --- a/TutorialMain.as +++ b/TutorialMain.as @@ -1,181 +1,181 @@ -//////////////////////////////////// -/// -/// Tutorial main - -/// This is mostly a TEST script -/// This just lets us load in and some other stuff -/// Will revisit when it comes time to actually making a tutorial - - -// TEMP -bool wasClicking = false; -Vec2f lastMousePos = Vec2f(0,0); -bool mousePressed = false; -// END - -void onInit(CRules@ this) -{ - if (!this.exists("default class")) - { - this.set_string("default class", "knight"); - } - - onRestart(this); - - // TEMP, PUT IN DIFFERENT FILE - AddColorToken("$T_D$", color_white); - AddColorToken("$T_0$", SColor(255, 25, 140, 255)); - AddColorToken("$green$", SColor(255, 100, 255, 100)); - - GUI::LoadFont("pixeled", CFileMatcher("uni0553.ttf").getFirst(), 26, true); -} - -void onRestart(CRules@ this) -{ - RegisterFileExtensionScript("Scripts/MapLoaders/LoadPNGMap.as", "png"); - AddMapScript(); - - RespawnAll(this); -} - -void RespawnAll(CRules@ this) -{ - for (int a = 0; a < getPlayerCount(); a++) - { - CPlayer@ player = getPlayer(a); - - if (player !is null) - onPlayerRequestSpawn(this, player); - } -} - -void AddMapScript() -{ - string[] name = getMap().getMapName().split('/'); - string mapName = name[name.length() - 1]; - mapName = mapName.substr(0,mapName.length() - 4); - - getMap().AddScript(mapName); -} - -void onNewPlayerJoin( CRules@ this, CPlayer@ player ) -{ - player.server_setTeamNum(0); -} - -void onPlayerRequestSpawn(CRules@ this, CPlayer@ player) -{ - Respawn(this, player); -} - -CBlob@ Respawn(CRules@ this, CPlayer@ player) -{ - if (player !is null) - { - // remove previous players blob - CBlob @blob = player.getBlob(); - - if (blob !is null) - { - CBlob @blob = player.getBlob(); - blob.server_SetPlayer(null); - blob.server_Die(); - } - - CBlob @newBlob = server_CreateBlob(this.get_string("default class"), 0, getSpawnLocation(player)); - newBlob.server_SetPlayer(player); - return newBlob; - } - - return null; -} - -Vec2f getSpawnLocation(CPlayer@ player) -{ - CMap@ map = getMap(); - if (player is null || map is null) { return Vec2f(0,0); } - - Vec2f[] spawns; - - switch (player.getTeamNum()) - { - case 0: - { - if (!map.getMarkers("blue spawn", spawns) && - !map.getMarkers("blue main spawn", spawns)) - { - return Vec2f_zero; - } - - return spawns[XORRandom(spawns.length)]; - } - } - - return Vec2f(0, 0); -} - -void onTick(CRules@ this) -{ - // TODO: DISABLE BOXES AND OTHER JUNK THAT WE DONT NEED FOR NOW - if (g_debug != 0) - { - - } -} - - -void onRender(CRules@ this) -{ - CBlob@ b = getLocalPlayerBlob(); - CControls@ c = getControls(); - if (g_debug == 0 || b is null || c is null) { return; } - - GUI::DrawText(getDriver().getWorldPosFromScreenPos(c.getInterpMouseScreenPos()) + "", Vec2f(20,25), SColor(255,255,255,255)); - - mousePressed = c.mousePressed1; - Vec2f currentPos = getDriver().getWorldPosFromScreenPos(c.getInterpMouseScreenPos()); - if (mousePressed && !wasClicking) - { - lastMousePos = currentPos; - } - - RenderSquare(currentPos); - - wasClicking = mousePressed; -} - -void RenderSquare(Vec2f currentPos) -{ - Vec2f topLeft = lastMousePos; - Vec2f botRight = currentPos; - - if (botRight.x < topLeft.x) - { - float temp = botRight.x; - botRight.x = topLeft.x; - topLeft.x = temp; - - if (botRight.y < topLeft.y) - { - temp = botRight.y; - botRight.y = topLeft.y; - topLeft.y = temp; - } - } - else if (topLeft.y > botRight.y) - { - float temp = topLeft.y; - topLeft.y = botRight.y; - botRight.y = temp; - } - - if (mousePressed) - { - GUI::DrawPane(getDriver().getScreenPosFromWorldPos(topLeft), getDriver().getScreenPosFromWorldPos(botRight), SColor(150, 0, 0, 0)); - } - - if (wasClicking && !mousePressed) - { - print("\nSector pos:\nVec2f" + topLeft +"\nVec2f" + botRight, SColor(255, 255, 100, 255)); - } +//////////////////////////////////// +/// +/// Tutorial main + +/// This is mostly a TEST script +/// This just lets us load in and some other stuff +/// Will revisit when it comes time to actually making a tutorial + + +// TEMP +bool wasClicking = false; +Vec2f lastMousePos = Vec2f(0,0); +bool mousePressed = false; +// END + +void onInit(CRules@ this) +{ + if (!this.exists("default class")) + { + this.set_string("default class", "knight"); + } + + onRestart(this); + + // TEMP, PUT IN DIFFERENT FILE + AddColorToken("$T_D$", color_white); + AddColorToken("$T_0$", SColor(255, 25, 140, 255)); + AddColorToken("$green$", SColor(255, 100, 255, 100)); + + GUI::LoadFont("pixeled", CFileMatcher("uni0553.ttf").getFirst(), 26, true); +} + +void onRestart(CRules@ this) +{ + RegisterFileExtensionScript("Scripts/MapLoaders/LoadPNGMap.as", "png"); + AddMapScript(); + + RespawnAll(this); +} + +void RespawnAll(CRules@ this) +{ + for (int a = 0; a < getPlayerCount(); a++) + { + CPlayer@ player = getPlayer(a); + + if (player !is null) + onPlayerRequestSpawn(this, player); + } +} + +void AddMapScript() +{ + string[] name = getMap().getMapName().split('/'); + string mapName = name[name.length() - 1]; + mapName = mapName.substr(0,mapName.length() - 4); + + getMap().AddScript(mapName); +} + +void onNewPlayerJoin( CRules@ this, CPlayer@ player ) +{ + player.server_setTeamNum(0); +} + +void onPlayerRequestSpawn(CRules@ this, CPlayer@ player) +{ + Respawn(this, player); +} + +CBlob@ Respawn(CRules@ this, CPlayer@ player) +{ + if (player !is null) + { + // remove previous players blob + CBlob @blob = player.getBlob(); + + if (blob !is null) + { + CBlob @blob = player.getBlob(); + blob.server_SetPlayer(null); + blob.server_Die(); + } + + CBlob @newBlob = server_CreateBlob(this.get_string("default class"), 0, getSpawnLocation(player)); + newBlob.server_SetPlayer(player); + return newBlob; + } + + return null; +} + +Vec2f getSpawnLocation(CPlayer@ player) +{ + CMap@ map = getMap(); + if (player is null || map is null) { return Vec2f(0,0); } + + Vec2f[] spawns; + + switch (player.getTeamNum()) + { + case 0: + { + if (!map.getMarkers("blue spawn", spawns) && + !map.getMarkers("blue main spawn", spawns)) + { + return Vec2f_zero; + } + + return spawns[XORRandom(spawns.length)]; + } + } + + return Vec2f(0, 0); +} + +void onTick(CRules@ this) +{ + // TODO: DISABLE BOXES AND OTHER JUNK THAT WE DONT NEED FOR NOW + if (g_debug != 0) + { + + } +} + + +void onRender(CRules@ this) +{ + CBlob@ b = getLocalPlayerBlob(); + CControls@ c = getControls(); + if (g_debug == 0 || b is null || c is null) { return; } + + GUI::DrawText(getDriver().getWorldPosFromScreenPos(c.getInterpMouseScreenPos()) + "", Vec2f(20,25), SColor(255,255,255,255)); + + mousePressed = c.mousePressed1; + Vec2f currentPos = getDriver().getWorldPosFromScreenPos(c.getInterpMouseScreenPos()); + if (mousePressed && !wasClicking) + { + lastMousePos = currentPos; + } + + RenderSquare(currentPos); + + wasClicking = mousePressed; +} + +void RenderSquare(Vec2f currentPos) +{ + Vec2f topLeft = lastMousePos; + Vec2f botRight = currentPos; + + if (botRight.x < topLeft.x) + { + float temp = botRight.x; + botRight.x = topLeft.x; + topLeft.x = temp; + + if (botRight.y < topLeft.y) + { + temp = botRight.y; + botRight.y = topLeft.y; + topLeft.y = temp; + } + } + else if (topLeft.y > botRight.y) + { + float temp = topLeft.y; + topLeft.y = botRight.y; + botRight.y = temp; + } + + if (mousePressed) + { + GUI::DrawPane(getDriver().getScreenPosFromWorldPos(topLeft), getDriver().getScreenPosFromWorldPos(botRight), SColor(150, 0, 0, 0)); + } + + if (wasClicking && !mousePressed) + { + print("\nSector pos:\nVec2f" + topLeft +"\nVec2f" + botRight, SColor(255, 255, 100, 255)); + } } \ No newline at end of file diff --git a/VanillaFixes/EmoteBubble.as b/VanillaFixes/EmoteBubble.as index 85fcb81..1850c71 100644 --- a/VanillaFixes/EmoteBubble.as +++ b/VanillaFixes/EmoteBubble.as @@ -1,83 +1,83 @@ -// Draw an emoticon - -#include "EmotesCommon.as"; - -void onInit(CBlob@ blob) -{ - blob.addCommandID("emote"); - - CSprite@ sprite = blob.getSprite(); - blob.set_u8("emote", Emotes::off); - blob.set_u32("emotetime", 0); - //init emote layer - CSpriteLayer@ emote = sprite.addSpriteLayer("bubble", "Entities/Common/Emotes/Emoticons.png", 32, 32, 0, 0); - emote.SetIgnoreParentFacing(true); - emote.SetFacingLeft(false); - - if (emote !is null) - { - emote.SetOffset(Vec2f(0, -sprite.getBlob().getRadius() * 1.5f - 16)); - emote.SetRelativeZ(100.0f); - { - Animation@ anim = emote.addAnimation("default", 0, true); - - for (int i = 0; i < Emotes::emotes_total; i++) - { - anim.AddFrame(i); - } - } - emote.SetVisible(false); - emote.SetHUD(true); - } -} - -void onTick(CBlob@ blob) -{ - blob.getCurrentScript().tickFrequency = 6; - // if (blob.exists("emote")) will show skull if none existant - - - // NOTE (REMOVE ME WHEN EVER) -> REMOVED STATIC CHECK - CSprite@ sprite = blob.getSprite(); - CSpriteLayer@ emote = sprite.getSpriteLayer("bubble"); - - const u8 index = blob.get_u8("emote"); - if (is_emote(blob, index) && !blob.hasTag("dead") && !blob.isInInventory()) - { - blob.getCurrentScript().tickFrequency = 1; - if (emote !is null) - { - emote.SetVisible(!isMouseOverEmote(emote)); - emote.animation.frame = index; - - emote.ResetTransform(); - - CCamera@ camera = getCamera(); - if (camera !is null) - { - f32 angle = -camera.getRotation() + blob.getAngleDegrees(); - emote.RotateBy(-angle, Vec2f(0, 20)); - } - } - } - else - { - emote.SetVisible(false); - } -} - -void onCommand(CBlob@ this, u8 cmd, CBitStream @params) -{ - if (cmd == this.getCommandID("emote")) - { - u8 emote = params.read_u8(); - u32 emotetime = params.read_u32(); - this.set_u8("emote", emote); - this.set_u32("emotetime", emotetime); - } -} - -void onClickedBubble(CBlob@ this, int index) -{ - set_emote(this, index); -} +// Draw an emoticon + +#include "EmotesCommon.as"; + +void onInit(CBlob@ blob) +{ + blob.addCommandID("emote"); + + CSprite@ sprite = blob.getSprite(); + blob.set_u8("emote", Emotes::off); + blob.set_u32("emotetime", 0); + //init emote layer + CSpriteLayer@ emote = sprite.addSpriteLayer("bubble", "Entities/Common/Emotes/Emoticons.png", 32, 32, 0, 0); + emote.SetIgnoreParentFacing(true); + emote.SetFacingLeft(false); + + if (emote !is null) + { + emote.SetOffset(Vec2f(0, -sprite.getBlob().getRadius() * 1.5f - 16)); + emote.SetRelativeZ(100.0f); + { + Animation@ anim = emote.addAnimation("default", 0, true); + + for (int i = 0; i < Emotes::emotes_total; i++) + { + anim.AddFrame(i); + } + } + emote.SetVisible(false); + emote.SetHUD(true); + } +} + +void onTick(CBlob@ blob) +{ + blob.getCurrentScript().tickFrequency = 6; + // if (blob.exists("emote")) will show skull if none existant + + + // NOTE (REMOVE ME WHEN EVER) -> REMOVED STATIC CHECK + CSprite@ sprite = blob.getSprite(); + CSpriteLayer@ emote = sprite.getSpriteLayer("bubble"); + + const u8 index = blob.get_u8("emote"); + if (is_emote(blob, index) && !blob.hasTag("dead") && !blob.isInInventory()) + { + blob.getCurrentScript().tickFrequency = 1; + if (emote !is null) + { + emote.SetVisible(!isMouseOverEmote(emote)); + emote.animation.frame = index; + + emote.ResetTransform(); + + CCamera@ camera = getCamera(); + if (camera !is null) + { + f32 angle = -camera.getRotation() + blob.getAngleDegrees(); + emote.RotateBy(-angle, Vec2f(0, 20)); + } + } + } + else + { + emote.SetVisible(false); + } +} + +void onCommand(CBlob@ this, u8 cmd, CBitStream @params) +{ + if (cmd == this.getCommandID("emote")) + { + u8 emote = params.read_u8(); + u32 emotetime = params.read_u32(); + this.set_u8("emote", emote); + this.set_u32("emotetime", emotetime); + } +} + +void onClickedBubble(CBlob@ this, int index) +{ + set_emote(this, index); +} diff --git a/gamemode.cfg b/gamemode.cfg index 0d3047a..1c7ec9d 100644 --- a/gamemode.cfg +++ b/gamemode.cfg @@ -1,61 +1,61 @@ - teams = team1.cfg; team2.cfg; - - gamemode_name = Tutorial2 - gamemode_info = Two teams spawn and fight each other to the death - - scripts = KAG.as; - TutorialMain.as; - CharacterHandler.as; - RequestSpawnOnDeath.as; - ChatCommands.as; - TeamMenuJustSpectator.as; - PlayerCamera.as; - - daycycle_speed = 0 # 1 day = X minutes; / 0 no cycle - daycycle_start = 0.3 # 0.0 midnight; 0.5 - midday; 1.0 midnight - minimap = false - - minimum_players_inteam = 1 - - autoassign_teams = no #team allocation is smart in this gamemode - - auto_bots = no - - playerrespawn_seconds = 10.0 - nearspawn_multiplier = 1.0 - switch_teams_onrestart = no # doesn't work yet - - death_points = 0 - kill_points = 10 - selfkill_points = -25 - - attackdamage_modifier = 0.5 - friendlydamage_modifier = 0.0 - -# map resources - mapresource_thickstone = 4 - mapresource_stone = 2 - mapresource_tree = 6 - mapresource_arrow = 1 - mapresource_gold = 2 -# end map resources - - restartmap_onlastplayer_disconnect = yes - mirrormap = yes - - coins_death_drop_percentage = 30 - coins_damage_enemy = 5 - coins_build_percentage = 10 - coins_bomb_cost = 20 - coins_arrows_cost = 1 - coins_heal_cost = 2 - coins_unit_cost = 50 - - room_config = - - waiting_for_respawn_message = "Wait to spawn on your team-mates..."; - - support_factor = 24 - support_added_vertical = 1 - support_cost_castle = 4 - support_cost_wood = 3 + teams = team1.cfg; team2.cfg; + + gamemode_name = Dev_Tutorial + gamemode_info = Two teams spawn and fight each other to the death + + scripts = KAG.as; + TutorialMain.as; + CharacterHandler.as; + RequestSpawnOnDeath.as; + ChatCommands.as; + TeamMenuJustSpectator.as; + PlayerCamera.as; + + daycycle_speed = 0 # 1 day = X minutes; / 0 no cycle + daycycle_start = 0.3 # 0.0 midnight; 0.5 - midday; 1.0 midnight + minimap = false + + minimum_players_inteam = 1 + + autoassign_teams = no #team allocation is smart in this gamemode + + auto_bots = no + + playerrespawn_seconds = 10.0 + nearspawn_multiplier = 1.0 + switch_teams_onrestart = no # doesn't work yet + + death_points = 0 + kill_points = 10 + selfkill_points = -25 + + attackdamage_modifier = 0.5 + friendlydamage_modifier = 0.0 + +# map resources + mapresource_thickstone = 4 + mapresource_stone = 2 + mapresource_tree = 6 + mapresource_arrow = 1 + mapresource_gold = 2 +# end map resources + + restartmap_onlastplayer_disconnect = yes + mirrormap = yes + + coins_death_drop_percentage = 30 + coins_damage_enemy = 5 + coins_build_percentage = 10 + coins_bomb_cost = 20 + coins_arrows_cost = 1 + coins_heal_cost = 2 + coins_unit_cost = 50 + + room_config = + + waiting_for_respawn_message = "Wait to spawn on your team-mates..."; + + support_factor = 24 + support_added_vertical = 1 + support_cost_castle = 4 + support_cost_wood = 3 diff --git a/mapcycle.cfg b/mapcycle.cfg index aa815a7..b94c796 100644 --- a/mapcycle.cfg +++ b/mapcycle.cfg @@ -1,2 +1,2 @@ -mapcycle = +mapcycle = KnightShowcase.png; \ No newline at end of file -- knotmirror 0.0.1