Fluorohydride / ygopro-core

ygopro script engine.
MIT License
321 stars 135 forks source link

add Card.IsTextMention #579

Closed salix5 closed 4 months ago

salix5 commented 4 months ago

@mercury233 @purerosefallen ocgapi: new API

extern "C" DECL_DLLEXPORT void set_mention_handler(mention_handler f);
//Set the mention_handler.
bool mention_handler(uint32 text_code, uint32 name_code)
//Check if the text of `text_code` mentions the name of `name_code`.

new function:

bool is_mention(uint32 text_code, uint32 name_code) {
    return thandler(text_code, name_code);
}

new Lua function

---Check if the text of this card mentions the name of `code`.
---@return boolean
---@param code integer
function Card.IsTextMention (code) end

It is the basic version. It can only check the card name which is NOT a setname. The card name which is also a setname can be checked by the old Auxiliary.IsCodeListed.

purerosefallen commented 4 months ago

Personally I don't like doing in this way, for the following reasons.

  1. String searching has a complexity of O(n^2) which slows server down being a regular condition check.
  2. This changes server deployment a lot, requiring to upload strings.conf as well. Btw is this commit tested on Mac / Linux? I doubt wstring works on those OSes. This is important because our server deploys on Linux.
  3. This also consumes server memory a lot, requiring to load every strings from cdb and strings.conf to memory. It's 7 MB in size for the current cards.cdb file. We could have 500 duels at once in our most popular servers, so if loading all of them, it would consume around 3.5 GB more memory, which is not acceptable.