Giter Club home page Giter Club logo

Comments (8)

 avatar commented on July 24, 2024

Actually, even after I fix all the above 5 places, the new scenes still doesn't pop up correctly... So I believe there is one more source...

from qsanguosha.

gutenye avatar gutenye commented on July 24, 2024

I agreed,

btw: the ai written in lua is totally a mess, It uses a lot of global variables everywhere. We really should rewrite the ai from scratch..

from qsanguosha.

 avatar commented on July 24, 2024

@gutenye If you can help refactor AI part or maintain AI of new heroes, that would be fabulous!

from qsanguosha.

gutenye avatar gutenye commented on July 24, 2024

sure, I'm learning lua and ai, and I try to write a new ai system in my ai branch, and it's a experiment branch, If everything goes well, I'll push my ai branch.

from qsanguosha.

haveatry823 avatar haveatry823 commented on July 24, 2024

建议用lua来配置和管理系统的小场景以及玩家自定义的小场景。

官方的小场景配置文件固定为 etc/customScenes/mini.lua
玩家自定义的小场景则任意命名,但是文件名必须是数字和英文下划线组成,lua为扩展名, 符合正则 \w+.lua
玩家的小场景管理的lua和系统的都放在 etc/customScenes 目录

程序启动的时候扫描并加载 etc/customScenes/*.lua
比如扫描到 customScenes 目录下有三个lua文件, mydiy.lua, test.lua, mini.lua
总是优先加载 mini.lua 官方这个,其余两个 mydiy.lua, test.lua 按照文件建立时间排序加载,也可以简单的按照文件名的字母排序

这些lua的文件结构如下:

--mini.lua
return
{

 ["mini_01"] = "狭路相逢",   --对应场景文件 mini_01.txt  建议强制要求以当前文件名mini 加下划线mini_为前缀
 ["mini_02"] = "谁与争锋",   --对应场景文件 mini_02.txt
 ["mini_03"] = "青梅煮酒",   --对应场景文件 mini_03.txt
    ....
    ["mini_33"] = "场景33的名字",   

}

--test.lua 玩家自定义的
return
{

    ["test_01"] = "场景名字一",      -- 对应 etc/customScenes/test_01.txt
    ["test_02] = "场景名字二",
    ["test_hello"] = "场景名字三",    -- 场景代号以 test_ 为前缀, 但不要求后面一定为数字
    ["test_world"] = "场景名字四",    -- 对应 etc/customScenes/test_world.txt

}

--mydiy.lua 论坛小场景区下载的另外一个玩家自定义的
return
{

    ["mydiy_ohoh"] = "哦哦DIYDIY",

}

然后 customScenes 目录下应该有对应的
mini_01.txt .. mini_33.txt , test_01.txt, test_02.txt , test_hello.txt, test_hello.txt, mydiy_ohoh.txt

程序按照加载lua的顺序加载这些 txt (要对txt做容错性检查,文件是否存在以及txt内容是否是错误的格式)

然后玩家玩小场景的时候, 玩完 mini_33 后点下一关,应该加载 test_01 的场景,
然后依次 test_02 .. test_world, 然后 mydiy_ohoh

可以在 engine.cpp 或者其他更恰当的位置添加一个方法,来加载这些 etc/customScenes/*.lua
并根据 lua的配置来加载 小场景的txt文件,其他地方比如settings.cpp调用这个 loader 函数

如此,开发步骤中 1, 3 , 4, 5 可合并或者简化

  1. In miniscenarios.cpp, add "ADD_CUSTOM_SCENARIO(34)"
  2. In etc/customScenes, add "34.txt"
  3. In lang/Zh_cn/Mini.lua, add ["_mini_34"] = "SceneName"
  4. In settings.cpp, change "Settings::S_MINI_SCENE_STAGE_TOTAL = 34"
  5. In lua/config.lua, change "for i=1, 34 do"
  6. update scenarios/miniscene.html

这样做不仅简化了开发者的开发步骤,也少了一个翻译步骤,因为这个是配置管理文件,也是标准翻译文件格式,

对玩家以及小场景制作者也有巨大收益。

玩家:
我下载了茶叶蛋小场景包的将近二十个 场景的txt文件, 玩的话,每玩一个就要
重新点击【自定义小场景】,点【装载】,点【确定】,而且场景之间没有关联的,
没有也不可能有【下一关】这样的按钮 ,每次都要反复操作这几个步骤,很不人性化
如果采取上述做法,可以把所有系统小场景和玩家自定义的全部串联起来。解决这个问题

小场景制作者:
可以为自己的小场景写特定的AI
现在所有的小场景,玩的时候 room:getMode() 都是 custom_scenario, 因为系统每次装载小场景的时候,
都把自定义的那个txt复制为 custom_scenario.txt 了,
如果按照上面的做法,玩家的文件名就可以被保留并传入系统(当然,文件名要符合正则 \w+.lua),
然后 room:getMode() 就可能是 "scenario_test_hello" 这样的字符串了,如果 mode 不好处理,就room:setTag("custom_scenario","scenario_test_hello")

在 smart-ai.lua最后写入类似下面的代码就可以为每个小场景指定单独的ai了

if string.sub(room:getMode(),1,10)=="scenario_" then
dofile("lua/ai/" .. string.sub(room:getMode(),10) .. "-ai.lua")
end

最后这种方式在读取玩家的进度记录的时候要额外小心,因为有可能玩家上次最后玩的那一关,下次启动程序的时候
那个对应的txt 场景文件已经被删除了, 做一下容错处理和文件检查机制,避免因此而导致程序crash

from qsanguosha.

gutenye avatar gutenye commented on July 24, 2024

用户自定义的建议放到 package/<name>/customScenes/ x.lua x.txt

参考 #37

from qsanguosha.

haveatry823 avatar haveatry823 commented on July 24, 2024

嗯,#37 的建议非常好, 但是目测要这样做的话,需要对程序进行比较大的调整(要判断是系统原生武将还是diy武将,然后再加载相应资源),牵涉面很大呢,而且同时影响到现有不少成熟的lua包的结构问题,神杀这边调整后,他们也要跟着调。
这个开发量应该不算小哦。

from qsanguosha.

haveatry823 avatar haveatry823 commented on July 24, 2024

进一步建议

lua可以写为

["test_hello"] = "场景名字三",    -- 场景代号以 test_ 为前缀, 但不要求后面一定为数字
[":test_hello"] ="使用双将,在你的下一个回合开始前击败张角/陈宫, 摸牌堆接下来是:黑桃K无懈可击,\
梅花6雷杀,红桃K闪,黑桃3酒,红桃Q桃,梅花Q借刀杀人,玩家首先行动;\
玩家的第二个回合开始时玩家失败。"

["test_world"] = "场景名字四",    -- 对应 etc/customScenes/test_world.txt
[":test_world"] = "使用双将,在甄姬的帮助下击败孙尚香、吴国太和大乔"

这样,小场景游戏开始的时候可以 用 prompt_box 或者 QMessageBox 提示玩家,这关的目标以及过关提示
这样的提示信息对于自定义场景尤其需要,因为官方的小场景有 scenarios/miniscene.html, 自定义的
还没有场景相关提示和信息

from qsanguosha.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.