Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
chencyr committed Jan 3, 2022
2 parents c8cbab2 + b0c084f commit a45f053
Show file tree
Hide file tree
Showing 22 changed files with 1,087 additions and 134 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
configs/*
configs/*
db-export
24 changes: 10 additions & 14 deletions core/game/actions/ident.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,22 @@ class Ident extends Action
async handler(from, to, args) {
const characterService = this.context.getService('character-service');

if (to.length == 0) {
if (! args[0]) {
throw new Error('Cannot find character error');
}
to.characterId = args[0];
}
else {
to = to[0];
}
let ids = to.map((item) => item.characterId)
.filter((item) => !(item === undefined))
.concat(args);

const characters = await characterService.getByIds(ids);
const character1 = await characterService.getById(from.characterId);
const character2 = await characterService.getById(to.characterId);

if (!character1 || !character2) {
if (!character1 || !characters.length > 0) {
throw new Error('Cannot find character error');
}

this.writeMsg(`${character1.getName()}${character2.getName()} 使用了鑑定 !!`)
.writeMsg(" ")
.writeMsg(board(character2))
characters.forEach((character2) => {
this.writeMsg(`[${character1.getName()}] 對 [${character2.getName()}] 使用了鑑定 !!`)
.writeMsg(" ")
.writeMsg(board(character2))
});
}
}

Expand Down
59 changes: 59 additions & 0 deletions core/game/actions/lair-trick-skill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const Skill = require('./skill');

const SendingBehavior = require('./skill/attack-sending-behavior');
const ReceivingBehavior = require('./skill/attack-receiving-behavior');

/**
* Skill action.
*/
class LairTrick extends Skill
{
/**
* Get action ID.
* @return {string}
*/
getId() {
return "lair-trick-skill";
}

/**
* Get action master name.
* @return {string}
*/
getNames() {
return [
"lair-trick",
"小白的騙術",
"小白騙術",
"騙術",
"小白大騙子",
"大騙子",
];
}

/**
* Get skill name. (should same as skill class file name)
* @return {string} standard name
*/
getSkillName() {
return "lair-trick"
}

/**
* Get sending behavior.
* @return {SendingBehavior}
*/
getSendingBehavior() {
return SendingBehavior;
}

/**
* Get receiving behavior.
* @return {ReceivingBehavior}
*/
getReceivingBehavior() {
return ReceivingBehavior
}
}

module.exports = LairTrick;
56 changes: 56 additions & 0 deletions core/game/actions/stick-attack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const Skill = require('./skill');

const SendingBehavior = require('./skill/attack-sending-behavior');
const ReceivingBehavior = require('./skill/attack-receiving-behavior');

/**
* Skill action.
*/
class StickAttack extends Skill
{
/**
* Get action ID.
* @return {string}
*/
getId() {
return "stick-attack-skill";
}

/**
* Get action master name.
* @return {string}
*/
getNames() {
return [
"stick-attack",
"木棒攻擊",
"木棒敲",
];
}

/**
* Get skill name. (should same as skill class file name)
* @return {string} standard name
*/
getSkillName() {
return "stick-attack"
}

/**
* Get sending behavior.
* @return {SendingBehavior}
*/
getSendingBehavior() {
return SendingBehavior;
}

/**
* Get receiving behavior.
* @return {ReceivingBehavior}
*/
getReceivingBehavior() {
return ReceivingBehavior
}
}

module.exports = StickAttack;
72 changes: 72 additions & 0 deletions core/game/actions/summon-old.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const Action = require('./action');

/**
* Summon action.
*/
class Summon extends Action
{
/**
* Constructor
* @param context
*/
constructor(context) {
super(context);
}

/**
* Get action ID.
* @return {string}
*/
getId() {
return "summon-old";
}

/**
* Get action master name.
* @return {string}
*/
getNames() {
return [
// "summon",
// "召喚",
];
}

/**
* Execute action for child class implement
* @param from
* @param to
* @param args
*/
async handler(from, to, args) {
const characterService = this.context.getService('character-service');

const player = await characterService.getById(from.characterId);
if (!player) {
this.writeMsg(`抓到了吼~你還沒加入!\n輸入 /join {角色名稱} 加入這個美好相殘的故事八`);
return this;
}

// TODO refactor method, static value

let level = args[0] || 15;
if(isNaN(level)) {
level = 15;
}
level = parseInt(level);
if(level < 0 || level > 10000) {
level = 15
}

level -= 1;

const monster = await characterService.new('monster', {level: level});

this.writeMsg(`${player.getName()} 成功召喚了一隻極為兇猛的怪物 !!`)
.writeMsg(`其偉大的名字為...「${monster.getName()}」!!!`)
.sendMsg()
.writeMsg(`${monster.getId()}`)
}
}

module.exports = Summon;
59 changes: 44 additions & 15 deletions core/game/actions/summon.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,30 @@ class Summon extends Action
return [
"summon",
"召喚",
"出來吧",
"出來啊",
"出來",
];
}

/**
* Add level for character
* @param character
* @param args
*/
addLevel(character, args) {
let level = args[1] || 0;
if(isNaN(level)) {
return;
}
level = parseInt(level);
if(level < 0 || level > 10000) {
return;
}

character.addLevels(level);
}

/**
* Execute action for child class implement
* @param from
Expand All @@ -47,25 +68,33 @@ class Summon extends Action
return this;
}

// TODO refactor method, static value
const condition = {
user_type: 'monster',
user_id: args[0],
};

let level = args[0] || 15;
if(isNaN(level)) {
level = 15;
}
level = parseInt(level);
if(level < 0 || level > 10000) {
level = 15
}
const character = await characterService.getByCondition(condition);
const newCharacter = character.clone();
this.addLevel(newCharacter, args);

const objectId = newCharacter.getId();
characterService.initWithObjectPool(newCharacter, objectId);

level -= 1;
this.writeMsg(`[${player.getName()}] 成功召喚了一個狠角色 !!`)
.writeMsg(`他的名字是 ... [${newCharacter.getName()}] !!!`)
.sendMsg();

const monster = await characterService.new('monster', {level: level});
const slogan = newCharacter.getSlogan();
if(slogan !== null) {
this.writeMsg(`${slogan}`);
}

const image = newCharacter.getImage();
if(image !== null) {
this.writeImg(`statics/${image}`);
}

this.writeMsg(`${player.getName()} 成功召喚了一隻極為兇猛的怪物 !!`)
.writeMsg(`其偉大的名字為...「${monster.getName()}」!!!`)
.sendMsg()
.writeMsg(`${monster.getId()}`)
this.writeMsg(`物件編號: ${objectId}`);
}
}

Expand Down
17 changes: 17 additions & 0 deletions core/game/components/game-object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Game base object.
*/
class GameObject
{
/**
* Constructor
* @param context {GameEngine}
*/
constructor(context) {
this.context = context;
}

}


module.exports = GameObject;
Empty file added core/game/components/index.js
Empty file.
Empty file added core/game/exceptions/index.js
Empty file.
34 changes: 28 additions & 6 deletions core/game/services/character-service/character/character.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ class Character
agi: 10,
int: 10,
luk: 10,
// TODO add gender
// gender: 1,
image: null,
slogan: null,
};


this.revive_timer = 0; // sec
this.revive_limit = 300; // sec

Expand All @@ -48,16 +47,30 @@ class Character

this.buffs = [];
this.skills = {};
}

this.setBuffs(initInfo.buffs);
/**
* Get character image.
* @return {string|null}
*/
getImage() {
return this.status.image;
}

/**
* Get character slogan
* @return {null}
*/
getSlogan() {
return this.status.slogan;
}

/**
* Set buff class list.
* Set buff by prototype list.
*
* @param buffs {array|undefined} [StandardBuff Class, StandardBuff Class, ...]
*/
setBuffs(buffs) {
setBuffsByPrototype(buffs) {
// TODO set by collection/object.
// TODO fix set duplicate buff problem

Expand All @@ -70,6 +83,15 @@ class Character
}
}

/**
* Set buffs by instance list.
* @param buffs
* @return {this}
*/
setBuffs(buffs) {
this.buffs = buffs;
}

/**
* Remove buff for the character
* @param buff
Expand Down
Loading

0 comments on commit a45f053

Please sign in to comment.