Star Ruler 2

Star Ruler 2

Large Game Customizations
Dalo Lorn 2015 年 6 月 26 日 上午 3:11
Example Moon-Adding Ability
For the sake of a complete demonstration, I'll also write up the simplest possible ability using the hook. Unfortunately, as the game's GUI doesn't yet support abilities with more than one target (though the rest of the game seems to), I'll have to compromise by making the artifact add the ability to a planet, and then having the planet cast that ability.

File name: scripts/definitions/Chrispy_effects.as

import hooks; import abilities; // I'm really not sure if I need this one, but I'll take it just in case. import artifacts; class AddMoonToPlanetFromObject : AbilityHook { Document doc("Adds a moon to the casting planet by destroying another object."); Argument objTarg(TT_Object); #section server void activate(Ability@ abl, any@ data, const Targets@ targs) const override { if(abl.obj is null || !abl.obj.isPlanet) return; Object@ targ = objTarg.fromConstTarget(targs).obj; if(targ is null) return; // This is the part where we add the moon. I'm taking the size of the moon from the target's radius - this could cause MAJOR graphical problems if you use it on anything larger than an asteroid, and maybe even with asteroids; you'll have to tweak it yourself. Planet@ planet = cast<Planet>(abl.obj); planet.addMoon(targ.radius); // This is where we kill the object, which may or may not be an asteroid. targ.destroy(); } #section all } // This hook is going to ensure we consume the ability-giving status from the artifact. class ConsumeStatus : AbilityHook { Document doc("Consumes one instance of a specific instance to cast the ability. Argument status(AT_Status, doc="Status effect to consume."); bool canActivate(const Ability@ abl, const Targets@ targs, bool ignoreCost) const override { return abl.obj.hasStatuses && abl.obj.getStatusStackCount(status.integer) != 0; } #section server void activate(Ability@ abl, any@ data, const Targets@ targs) const override { abl.obj.removeStatusInstanceOfType(status.integer); } #section all }

File name: data/artifacts/MoonMachine.txt

Artifact: MoonMachine Name: #ART_MOON_MACHINE Description: #ART_MOON_MACHINE_DESC Frequency: 0.5 Model: ArtifactAdvanced Ability: MoonMachine

File name: data/abilities/artifacts/MoonMachine.txt

Ability: MoonMachine Name: #ABL_MOON_MACHINE Description: #ABL_MOON_MACHINE_DESC Icon: HexagonSubsystems::6 * #e900ff Target: targ = Object // You figure out what cost you want to set. Oh, and pick an icon that isn't from the Buster Machine. :P Energy Cost: 0 ReduceEnergyCostSystemFlag(0.75, CheapArtifacts) TargetFilterType(targ, Planet) TargetFilterOwned(targ) Trigger(targ, AddStatus(MoonMachine)) // I'm going to bunch this second ability up with the Moon Machine, seeing as they're part of the same artifact's functionality. Ability: PullAsteroidIntoOrbit Name: #ABL_MOON_MACHINE_2 Description: #ABL_MOON_MACHINE_2_DESC Icon: HexagonSubsystems::6 * #e900ff Target: targ = Object TargetFilterType(targ, Asteroid) Chrispy_effects::AddMoonToPlanetFromObject(targ) Chrispy_effects::ConsumeStatus(MoonMachine)

File name: data/statuses/MoonMachine.txt

Status: MoonMachine Visible To: Nobody Collapses: True GrantAbility(PullAsteroidIntoOrbit)

And there we have it, an artifact which lets a planet pull an asteroid into orbit as a moon! (Edit: Err, no, we don't. I didn't finish ConsumeStatus. Oh well, it's corrected now.)
最后由 Dalo Lorn 编辑于; 2015 年 6 月 26 日 上午 3:14
< >
正在显示第 1 - 2 条,共 2 条留言
ChrisPikula  [开发者] 2015 年 6 月 26 日 上午 10:49 
That is wonderful! :-D
grffnhwk 2016 年 8 月 26 日 上午 8:58 
Not sure if you're sub'd to this discussion stll. In an effort to learn AS I tried putting this all together and the artifact shows up, applied the effect to a planet, but fails to do anything when the ability is performed on any asteroid. Is there something I'm missing?
最后由 grffnhwk 编辑于; 2016 年 8 月 26 日 上午 8:59
< >
正在显示第 1 - 2 条,共 2 条留言
每页显示数: 1530 50