-
Notifications
You must be signed in to change notification settings - Fork 0
/
banish.js
55 lines (54 loc) · 2.09 KB
/
banish.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const util = require("./util.js");
module.exports.banish = (gameState, targetName, bot) =>{
population = gameState.population
person = util.personByName(targetName, gameState)
console.log("In banish lib for "+targetName)
if (person){
targetName = person.name
}
if (population[targetName]){
person = util.personByName(targetName, gameState)
if (!gameState.banished){
gameState.banished = {}
}
gameState.banished[targetName] = person
// removing the player from the banish list is a pain.
delete population[targetName]
util.messageChannel(targetName+' is banished from the tribe',gameState, bot)
for (childName in gameState.children){
child = gameState.children[childName]
console.log(childName+' is getting checked')
// remove the unborn children
if (child.mother == targetName && child.age < 4 ){
gameState.banished[childName] = child;
delete gameState.children[childName]
}
if (person.guarding && person.guarding.indexOf(childName) > -1 ){
childIndex = person.guarding.indexOf(childName)
if (childIndex > -1) {
person.guarding.splice(childIndex, 1);
}
util.messageChannel(targetName+' stops guarding '+childName, gameState, bot)
}
}
// clean up inviteList
for (memberName in population){
if (memberName == targetName){
continue;
}
member = population[memberName]
if (member.inviteList){
targetIndex = member.inviteList.indexOf(targetName)
if (targetIndex > -1 ){
member.inviteList.splice(targetIndex, 1)
}
}
}
const name = person.name
gameState.banished[targetName] = person
return
} else {
console.log("Failed to get the person; banish fails")
util.messageChannel(targetName+" was not found in the tribe")
}
}