这个提交包含在:
2020-07-17 19:32:46 +08:00
父节点 ff0af23dee
当前提交 61a6d3633c
共有 8 个文件被更改,包括 354 次插入 和 2 次删除

112
Core.Class.js 普通文件
查看文件

@ -0,0 +1,112 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
exports.Weapons = new Map();
exports.WeaponsWarhead = new Map();
class GameBlock {
}
exports.GameBlock = GameBlock;
exports.GameBlocks = new Map();
class GameLocation {
}
exports.GameLocation = GameLocation;
class GamePlayer {
constructor() {
this.Language = new GameLanguage("zh_cn");
this.Money = 13000;
this.Factorys = new Map();
this.Units = [];
}
}
exports.GamePlayer = GamePlayer;
class GameLanguage {
Get(Source) {
var Result = this.Pack[Source.toString()];
if (Result) {
return new String(Result);
}
else {
return new String(Source);
}
}
constructor(Language) {
this.Language = Language;
this.Pack = fs.readFileSync(`./Language.${this.Language}.json`);
}
}
exports.GameLanguage = GameLanguage;
class GameObjectRoot {
UnderAttack(Weapon, Attacker) {
if (this.Bind.Broken) {
return;
}
exports.Weapons.get(Weapon.valueOf()).Warhead.Attack(this, exports.Weapons.get(Weapon.valueOf()), Attacker);
if (this.Health > 0) {
this.Bind.Broken = true;
}
}
constructor(Loader) {
const that = Loader;
//定义 that 为 Loader
this.Health = new Number(that.Health);
this.Cost = new Number(that.Cost);
this.Name = new String(that.Name);
this.Size = new Number(that.Size);
this.Weapon = new String(that.Weapon);
this.Type = new String(that.Type);
this.BuildAble = new Boolean(that.BuildAble);
}
}
exports.GameObjectRoot = GameObjectRoot;
class GameObject {
constructor(Root, Owner) {
this.Root = new GameObjectRoot(Root);
this.Root.Bind = this;
this.Health = this.Root.Health;
this.Leven = 1;
this.Owner = Owner;
this.Owner.Money = this.Owner.Money.valueOf() - this.Root.Cost.valueOf();
this.Owner.Units[this.Owner.Units.length] = this;
this.Broken = false;
if (this.Root.Type.valueOf() != "Building") {
// this.Location = this.Owner.Factorys.get(this.Root.Type.valueOf())[0].Location;
}
// this.Location.Units[this.Location.Units.length] = this;
// this.Location.UsedSize = this.Location.UsedSize.valueOf() + this.Root.Size.valueOf();
}
;
Attack(that) {
if (this.Broken) {
return;
}
that.Root.UnderAttack(this.Root.Weapon, this.Root);
}
}
exports.GameObject = GameObject;
class GameWeapon {
constructor(Loader) {
const that = Loader;
this.Hurt = that.Hurt;
this.Warhead = exports.WeaponsWarhead.get(that.Warhead.valueOf());
this.Spawner_SpawnGameObjectRoot = that.Spawner_SpawnGameObjectRoot;
}
}
exports.GameWeapon = GameWeapon;
class GameWeaponWarhead {
Attack(GOR, GW, ATT) {
// 真的就Empty呗;
return;
}
;
constructor(Attack) {
this.Attack = Attack;
}
}
exports.GameWeaponWarhead = GameWeaponWarhead;

36
Core.Init.js 普通文件
查看文件

@ -0,0 +1,36 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const GameCoreClass = __importStar(require("./Core.Class"));
const fs = __importStar(require("fs"));
exports.GameObjectRoots = new Map();
exports.RulesSourceData = JSON.parse(fs.readFileSync("./Rules.json").toString());
exports.RulesSourceDataOfGameObjectRoots = exports.RulesSourceData["GameObject"];
exports.RulesSourceDataOfGameWeapons = exports.RulesSourceData["Weapons"];
Object.keys(exports.RulesSourceDataOfGameObjectRoots).forEach((v) => {
exports.GameObjectRoots.set(v, new GameCoreClass.GameObjectRoot(exports.RulesSourceDataOfGameObjectRoots[v]));
});
// 弹头是代码里面写好的
GameCoreClass.WeaponsWarhead.set("Standard", new GameCoreClass.GameWeaponWarhead((GOR, GW, ATT) => {
// 标准武器弹头
// 被攻击.血量 = 被攻击.血量 - 武器.伤害 * 随机(0.75,1.25)
GOR.Bind.Health = GOR.Bind.Health.valueOf() - GW.Hurt.valueOf() * (Math.random() + 0.25);
}));
GameCoreClass.WeaponsWarhead.set("Spawner", new GameCoreClass.GameWeaponWarhead((GOR, GW, ATT) => {
// 生成武器
var SpawnGameObjectRoot = exports.GameObjectRoots.get(GW.Spawner_SpawnGameObjectRoot.valueOf());
var Spawn = new GameCoreClass.GameObject(SpawnGameObjectRoot, ATT.Bind.Owner);
}));
GameCoreClass.WeaponsWarhead.set("Kill", new GameCoreClass.GameWeaponWarhead((GOR, GW, ATT) => {
// 一击毙命
GOR.Bind.Broken = true;
}));
Object.keys(exports.RulesSourceDataOfGameWeapons).forEach((v) => {
GameCoreClass.Weapons.set(v, new GameCoreClass.GameWeapon(exports.RulesSourceDataOfGameWeapons[v.valueOf()]));
});

5
Language.zh_cn.json 普通文件
查看文件

@ -0,0 +1,5 @@
{
"LanguageType":"简体中文",
"OnlineRTS":"在线即时战略游戏",
"Cost":"价格"
}

查看文件

@ -54,5 +54,10 @@
"Allow":true,
"FindIn":"fs",
"Path":"农村.js"
}
},
"ORTS":{
"Allow":"true",
"FindIn":"fs",
"Path":"User.Ai.js"
}
}

1
ORTSDataBase.json 普通文件
查看文件

@ -0,0 +1 @@
{}

46
Rules.json 普通文件
查看文件

@ -0,0 +1,46 @@
{
"Settings":{
"Name":"OnlineRTS Default Game Rules"
},
"Factions":{
},
"GameObject":{
"A1坦克":{
"Name":"A1Tank",
"Health":100,
"Weapon":"A1Weapon",
"Size":1,
"Type":"Tank",
"Cost":100
},
"A2坦克":{
"Name":"A2Tank",
"Health":200,
"Weapon":"A2Weapon",
"Size":1,
"Type":"Tank",
"Cost":100
},
"建造厂":{
"Name":"建造厂",
"Health":5000,
"Weapon":"Empty",
"Size":10,
"Type":"Building",
"Cost":3000,
"BuildAble":false
}
},
"Weapons":{
"A1Weapon":{
"Hurt":30,
"Warhead":"Standard"
},
"A2Weapon":{
"Hurt":70,
"Spawner_SpawnGameObjectRoot":"A1坦克",
"Warhead":"Spawner"
}
}
}

147
User.Ai.js 普通文件
查看文件

@ -0,0 +1,147 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
// ORTS For OnlineAi Interface
const CoreClass = __importStar(require("./Core.Class"));
const CoreInit = __importStar(require("./Core.Init"));
const AiCore = __importStar(require("./Core"));
const fs = __importStar(require("fs"));
var ORTSData = {};
var ORTSGameObjectPointer = new Map();
ORTSData.Player = new Map();
if (fs.existsSync("./ORTSDataBase.json")) {
var ORTSDataBase = JSON.parse(fs.readFileSync("./ORTSDataBase.json").toString());
Object.keys(ORTSDataBase).forEach((v, i) => {
ORTSData.Player.set(new Number(v), ORTSData[v]);
});
}
AiCore.AddListener((AiConnect, AiMessage) => {
if (AiMessage.message.substr(0, 4) != "ORTS") {
return;
}
var UserData = ORTSData.Player.get(AiCore.GetUser(AiMessage.user_id));
var Command = AiMessage.message.replace("ORTS", "");
if (Command == "信息") {
if (!UserData) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},你没有注册ORTS.`);
}
else {
AiCore.frame.SendMsg(AiConnect, AiMessage, `用户名称:${AiMessage.sender.nickname}\r\n用户资金:${UserData.Money}\r\n用户单位:${UserData.Units.length}`);
}
return;
}
if (Command.substr(0, 2) == "建造") {
if (!UserData) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},你没有注册ORTS.`);
return;
}
var BuildingUnitName = Command.replace("建造", "");
if (!CoreInit.GameObjectRoots.has(BuildingUnitName)) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiMessage.user_id)},没有这个单位`);
return;
}
var BuildingGameObjectRoot = CoreInit.GameObjectRoots.get(BuildingUnitName);
if (UserData.Money < BuildingGameObjectRoot.Cost) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiMessage.user_id)},你的资金不足.`);
return;
}
console.log(BuildingGameObjectRoot);
if (BuildingGameObjectRoot.BuildAble == false) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiMessage.user_id)},此单位不可建造`);
return;
}
new CoreClass.GameObject(BuildingGameObjectRoot, UserData);
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiMessage.user_id)},建造完成.`);
}
if (Command.substr(0, 2) == "选择") {
if (!UserData) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},你没有注册ORTS.`);
return;
}
var Chooser = new Number(Command.replace("选择", "")).valueOf();
if (isNaN(Chooser)) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},请输入一个具体的编号`);
return;
}
if (!UserData.Units[Chooser]) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},没有这个单位`);
return;
}
ORTSGameObjectPointer.set(AiMessage.user_id, UserData.Units[Chooser]);
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},已选中单位<${UserData.Language.Get(UserData.Units[Chooser].Root.Name)}>`);
}
if (Command == "查看") {
if (!UserData) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},你没有注册ORTS.`);
return;
}
if (!ORTSGameObjectPointer.has(AiMessage.user_id)) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},你没有选中单位`);
return;
}
var UnitStatus = (() => { if (ORTSGameObjectPointer.get(AiMessage.user_id).Broken) {
return "损毁";
}
else {
return "正常";
} })();
AiCore.frame.SendMsg(AiConnect, AiMessage, `选中单位<${UserData.Language.Get(ORTSGameObjectPointer.get(AiMessage.user_id).Root.Name)}>\r\n状态:${UnitStatus}\r\n血量:${ORTSGameObjectPointer.get(AiMessage.user_id).Health}\\${ORTSGameObjectPointer.get(AiMessage.user_id).Root.Health}\r\n等级:${ORTSGameObjectPointer.get(AiMessage.user_id).Leven}`);
return;
}
if (Command == "列表") {
if (!UserData) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},你没有注册ORTS.`);
return;
}
var Ret = "单位列表:";
UserData.Units.forEach((v, i) => {
Ret = Ret + "\r\n" + i + "." + UserData.Language.Get(v.Root.Name) + (() => { if (v.Broken) {
return "[阵亡]";
}
else {
return "";
} })();
});
AiCore.frame.SendMsg(AiConnect, AiMessage, Ret);
}
if (Command.substr(0, 2) == "攻击") {
if (!UserData) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},你没有注册ORTS.`);
return;
}
var AttackPointer = new Number(Command.replace("攻击", "")).valueOf();
if (AiCore.frame.GetAt(AiConnect, AiMessage)) {
AttackPointer = new Number(AiCore.frame.GetAt(AiConnect, AiMessage)).valueOf();
}
if (isNaN(AttackPointer)) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},请提供一个用户.`);
return;
}
if (!ORTSGameObjectPointer.has(AiMessage.user_id)) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},你没有选中单位`);
return;
}
if (!ORTSData.Player.has(AttackPointer)) {
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},这个用户暂未注册ORTS`);
return;
}
var UnderAttacker = ORTSData.Player.get(AttackPointer);
for (var UnitID = 0; (UnitID < UnderAttacker.Units.length) && (!UnderAttacker.Units[UnitID].Broken); UnitID++) { }
ORTSGameObjectPointer.get(AiMessage.user_id).Attack(UnderAttacker.Units[UnitID]);
return;
}
if (Command == "注册") {
UserData = new CoreClass.GamePlayer();
UserData.Units[0] = new CoreClass.GameObject(CoreInit.GameObjectRoots.get("建造厂"), UserData);
ORTSData.Player.set(AiCore.GetUser(AiMessage.user_id), UserData);
AiCore.frame.SendMsg(AiConnect, AiMessage, `${AiCore.frame.At(AiCore.GetUser(AiMessage.user_id))},注册成功`);
return;
}
fs.writeFile("./ORTSDataBase.json", JSON.stringify(ORTSData.Player), (err) => { });
});

查看文件

@ -1 +1 @@
{"固定资产":{"862869995":550,"927980270":1200,"1285908631":500,"2868445034":550},"利息":{"862869995":"20206","927980270":"20206","2868445034":"20206"},"领工资":{"927980270":"202061"},"签到":{"862869995":"202061","927980270":"202061","1285908631":"202061","2868445034":"202061"},"RedPacketPool":0,"SandBox":{},"目标":{},"AITalk":{"Core":true},"板砖":{},"公会系统":{"927980270":"共学社"},"AIEnable":{"588932037":true,"776148636":true,"966138955":true}}
{"固定资产":{"862869995":550,"927980270":2301,"1285908631":500,"2284888681":899,"2868445034":550},"利息":{"862869995":"20206","927980270":"20206","2868445034":"20206"},"领工资":{"927980270":"202064","2284888681":"202064"},"签到":{"862869995":"202061","927980270":"202064","1285908631":"202061","2284888681":"202064","2868445034":"202061"},"RedPacketPool":0,"SandBox":{},"目标":{},"AITalk":{"927980270":false,"Core":true},"板砖":{},"公会系统":{"927980270":"共学社"},"AIEnable":{"545541668":true,"588932037":true,"776148636":true,"963936042":true,"966138955":true}}