Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jice-nospam committed Oct 9, 2016
1 parent 4598b1e commit 88aab1d
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 187 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 0.7.0 / 06-oct-2016
# 0.7.0 / 09-oct-2016
* switched to typescript 2.0 (this breaks node support for unit tests)

* Yendor toolkit
Expand Down
2 changes: 1 addition & 1 deletion src/fwk/actors/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export class Actor extends Yendor.TimedEntity implements Yendor.IPersistent {
}
}
if (this.ai) {
let condDesc: string|undefined = this.ai.getConditionDescription();
let condDesc: string|undefined = this.ai.getConditionDescription(this);
if (condDesc) {
desc += ", " + condDesc;
}
Expand Down
20 changes: 16 additions & 4 deletions src/fwk/actors/actor_condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ export class Condition {
}
}

private static condNames = ["confused", "stunned", "frozen", "regeneration", "overencumbered", "life detection"];
private static condNames = [
undefined,
"confused",
"stunned",
"frozen",
"regeneration",
"overencumbered",
"life detection",
];

public readonly onlyIfActive: boolean;
public readonly initialTime: number;
Expand All @@ -47,22 +55,26 @@ export class Condition {
protected _time: number;
protected _type: ConditionTypeEnum;
protected name: string|undefined;
protected noDisplay: boolean;
protected _noDisplay: boolean;
protected _noCorpse: boolean;

protected constructor(def: IConditionDef) {
if (def) {
this.initialTime = def.nbTurns;
this._time = def.nbTurns;
this._type = def.type;
this.noDisplay = def.noDisplay || false;
this._noDisplay = def.noDisplay || false;
this.name = def.name;
this.onlyIfActive = def.onlyIfActive || false;
this._noCorpse = def.noCorpse || false;
}
}

get type() { return this._type; }
get time() { return this._time; }
public getName() { return this.noDisplay ? undefined : this.name ? this.name : Condition.condNames[this._type]; }
get noCorpse() { return this._noCorpse; }
get noDisplay() { return this._noDisplay; }
public getName() { return this._noDisplay ? undefined : this.name ? this.name : Condition.condNames[this._type]; }

/**
* Function: onApply
Expand Down
46 changes: 28 additions & 18 deletions src/fwk/actors/actor_creature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,23 @@ export class Ai implements IActorFeature, IContainerListener {
}
}

public getConditionDescription(): string|undefined {
return this._conditions && this._conditions.length > 0 ? this._conditions[0].getName() : undefined;
public getConditionDescription(owner: Actor): string|undefined {
// find the first valid condition
if (! this._conditions) {
return undefined;
}
let i: number = 0;
while ( i < this._conditions.length ) {
let condition: Condition = this._conditions[i];
if ( condition.getName()) {
if (! condition.noDisplay
&& (!condition.noCorpse || ! owner.destructible || !owner.destructible.isDead())) {
return condition.getName();
}
}
i++;
}
return undefined;
}

public hasActiveConditions(): boolean {
Expand Down Expand Up @@ -253,19 +268,14 @@ export class Ai implements IActorFeature, IContainerListener {
}
}

// private activateActor(owner: Actor, actor: Actor) {
// if (actor.activable) {
// actor.activable.switchLever(actor, owner);
// owner.wait(this._walkTime);
// } else if (actor.container && this.lootHandler) {
// this.lootHandler.lootContainer(owner, actor);
// }
// }

private checkOverencumberedCondition(container: Container, owner: Actor) {
if (!this.hasCondition(ConditionTypeEnum.OVERENCUMBERED)
&& container.computeTotalWeight() >= container.capacity * OVERENCUMBERED_THRESHOLD) {
this.addCondition(Condition.create({ nbTurns: -1, type: ConditionTypeEnum.OVERENCUMBERED }), owner);
this.addCondition(Condition.create({
nbTurns: -1,
type: ConditionTypeEnum.OVERENCUMBERED,
noCorpse: true,
}), owner);
} else if (this.hasCondition(ConditionTypeEnum.OVERENCUMBERED)
&& container.computeTotalWeight() < container.capacity * OVERENCUMBERED_THRESHOLD) {
this.removeCondition(ConditionTypeEnum.OVERENCUMBERED);
Expand Down Expand Up @@ -434,10 +444,10 @@ export class PlayerAi extends Ai {
}
// note : this time is spent before you select the target. loading the projectile takes time
owner.wait(weapon.ranged.loadTime);
weapon.ranged.fire(owner).then((fired: boolean) => {
if ( fired ) {
owner.wait(this.walkTime);
}
weapon.ranged.fire(owner, weapon).then((_fired: boolean) => {
// if ( fired ) {
// owner.wait(this.walkTime);
// }
});
}

Expand All @@ -458,7 +468,7 @@ export class PlayerAi extends Ai {
return;
}
staff.magic.zap(staff, owner).then((_zapped: boolean) => {
owner.wait(this.walkTime);
//owner.wait(this.walkTime);
});
}

Expand All @@ -481,7 +491,7 @@ export class PlayerAi extends Ai {

private throwItem(owner: Actor, item: Actor) {
if (item.pickable) {
item.pickable.throw(item, Actor.specialActors[SpecialActorsEnum.PLAYER]).then(() => {
item.pickable.throw(item, Actor.specialActors[SpecialActorsEnum.PLAYER], false).then(() => {
owner.wait(this.walkTime);
});
}
Expand Down
13 changes: 8 additions & 5 deletions src/fwk/actors/actor_def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ export enum EffectTypeEnum {

export interface IEffectDef {
type: EffectTypeEnum;
data?: IInstantHealthEffectDef | ITeleportEffectDef | IConditionEffectDef | IEventEffectDef;
/** effect can only affect one actor (arrow) or several (explosion) */
singleActor?: boolean;
}

export interface IEventEffectDef {
export interface IEventEffectDef extends IEffectDef {
eventType: string;
eventData: any;
}

export interface IInstantHealthEffectDef {
export interface IInstantHealthEffectDef extends IEffectDef {
amount: number;
/** does this effect also work on deads (defult : false) */
canResurrect?: boolean;
Expand All @@ -89,7 +90,7 @@ export interface IInstantHealthEffectDef {
failureMessage?: string;
}

export interface ITeleportEffectDef {
export interface ITeleportEffectDef extends IEffectDef {
successMessage: string;
}

Expand Down Expand Up @@ -154,11 +155,13 @@ export interface IConditionDef {
noDisplay?: boolean;
/** for activable items */
onlyIfActive?: boolean;
/** only display on living creatures (for example confused) */
noCorpse?: boolean;
/** to override the condition's default name */
name?: string;
}

export interface IConditionEffectDef {
export interface IConditionEffectDef extends IEffectDef {
condition: IConditionDef;
successMessage: string;
}
Expand Down
Loading

0 comments on commit 88aab1d

Please sign in to comment.