Initialize local project and fix ranch growth synchronization
This commit is contained in:
@@ -0,0 +1,290 @@
|
||||
package net.pixvi.myr.panel.ground
|
||||
{
|
||||
import com.greensock.TweenMax;
|
||||
import flash.events.Event;
|
||||
import flash.geom.Rectangle;
|
||||
import net.pixvi.myr.element.mon.MonsterVo;
|
||||
import net.pixvi.myr.element.stack.StackVo;
|
||||
import net.pixvi.myr.event.MYREvent;
|
||||
import net.pixvi.myr.panel.build.BuildVo;
|
||||
import net.pixvi.myr.view.mon.GroundMon;
|
||||
import net.pixvi.myr.view.mon.StackGroundMon;
|
||||
import net.pixvi.myr.view.mon.StoreGroundMon;
|
||||
import net.pixvi.myr.view.stack.StackView;
|
||||
import net.pixvi.pfw.display.PiSprite;
|
||||
import net.pixvi.pfw.driver.EnterFrameDriver;
|
||||
import net.pixvi.pfw.utils.ArrayUtil;
|
||||
import net.pixvi.pfw.utils.Caller;
|
||||
import net.pixvi.pfw.utils.Jumper;
|
||||
import net.pixvi.pfw.utils.Random;
|
||||
import net.pixvi.pfw.utils.Sorter;
|
||||
|
||||
public class GroundArea extends PiSprite
|
||||
{
|
||||
|
||||
public var area:Rectangle;
|
||||
|
||||
public var monsters:Array = [];
|
||||
|
||||
public var builds:Array;
|
||||
|
||||
public var stacks:Array = [];
|
||||
|
||||
public var stackPoints:Object;
|
||||
|
||||
public var overFixRule:int = 1;
|
||||
|
||||
public var sortJump:Jumper = new Jumper(3);
|
||||
|
||||
public var randomPandding:Number = 120;
|
||||
|
||||
public var libMode:Boolean = false;
|
||||
|
||||
public function GroundArea(area:Rectangle, fixScale:Boolean = true)
|
||||
{
|
||||
this.area = new Rectangle(area.x,area.y,area.width,area.height);
|
||||
super();
|
||||
}
|
||||
|
||||
public function addMonsterByVo(mon:MonsterVo) : GroundMon
|
||||
{
|
||||
var nm:GroundMon = new GroundMon(mon,this);
|
||||
nm.moveToRandomPoint();
|
||||
nm.buildView();
|
||||
addMonster(nm);
|
||||
return nm;
|
||||
}
|
||||
|
||||
public function addStackMonsterByVo(mon:MonsterVo, isEnviroment:Boolean = false) : GroundMon
|
||||
{
|
||||
var nm:GroundMon = new StackGroundMon(mon,this,isEnviroment);
|
||||
nm.moveToRandomPoint();
|
||||
nm.buildView();
|
||||
addMonster(nm,isEnviroment);
|
||||
return nm;
|
||||
}
|
||||
|
||||
public function addBuildByVo(build:BuildVo) : void
|
||||
{
|
||||
var bdv:GroundBuildView = new GroundBuildView(build);
|
||||
bdv.x = build.x;
|
||||
bdv.y = build.y;
|
||||
bdv.buildView();
|
||||
}
|
||||
|
||||
public function getMonByMid(mid:Number) : GroundMon
|
||||
{
|
||||
var i:int = 0;
|
||||
var len:int = int(monsters.length);
|
||||
for(i = 0; i < len; )
|
||||
{
|
||||
if(monsters[i].vo.id == mid)
|
||||
{
|
||||
return monsters[i];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function addStoreMonsterByVo(mon:MonsterVo) : GroundMon
|
||||
{
|
||||
var nm:GroundMon = new StoreGroundMon(mon,this);
|
||||
nm.moveToRandomPoint();
|
||||
nm.buildView();
|
||||
addMonster(nm);
|
||||
return nm;
|
||||
}
|
||||
|
||||
public function removeMonsterByVo(mon:MonsterVo) : void
|
||||
{
|
||||
for each(var groundmon:GroundMon in monsters)
|
||||
{
|
||||
if(groundmon.vo == mon)
|
||||
{
|
||||
removeMonster(groundmon);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function addStackByVo(stack:StackVo = null, position:int = 0) : void
|
||||
{
|
||||
var sv:StackView = null;
|
||||
if(position == 3)
|
||||
{
|
||||
sv = new StackView(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
sv = new StackView();
|
||||
}
|
||||
sv.position = position;
|
||||
sv.init(stack,this);
|
||||
if(stackPoints[position] != null)
|
||||
{
|
||||
sv.x = stackPoints[position].x;
|
||||
sv.y = stackPoints[position].y;
|
||||
}
|
||||
else
|
||||
{
|
||||
sv.x = Random.number(area.left,area.right);
|
||||
sv.y = Random.number(area.top,area.bottom);
|
||||
}
|
||||
sv.startOrResume();
|
||||
stacks.push(sv);
|
||||
addChild(sv);
|
||||
}
|
||||
|
||||
public function getStackByMid(mid:Number) : StackView
|
||||
{
|
||||
for each(var s:StackView in stacks)
|
||||
{
|
||||
if(s.vo != null && s.vo.monsterId == mid)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getStackBySid(sid:int) : StackView
|
||||
{
|
||||
for each(var s:StackView in stacks)
|
||||
{
|
||||
if(s.vo != null && s.vo.id == sid)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getStackByPosition(position:int) : StackView
|
||||
{
|
||||
for each(var s:StackView in stacks)
|
||||
{
|
||||
if(s.vo != null && s.vo.position == position)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function addBuild(build:GroundBuildView) : void
|
||||
{
|
||||
builds.push(build);
|
||||
addChild(build);
|
||||
}
|
||||
|
||||
public function addMonster(mon:GroundMon, isEnviroment:Boolean = false) : void
|
||||
{
|
||||
if(!isEnviroment)
|
||||
{
|
||||
mon.addEventListener(MYREvent.REMOVE,removeGroundMonHandler);
|
||||
}
|
||||
else
|
||||
{
|
||||
mon.mouseChildren = mon.mouseEnabled = false;
|
||||
}
|
||||
monsters.push(mon);
|
||||
addChild(mon);
|
||||
}
|
||||
|
||||
public function removeMonster(mon:GroundMon) : void
|
||||
{
|
||||
if(contains(mon))
|
||||
{
|
||||
mon.mouseChildren = mon.mouseEnabled = false;
|
||||
mon.stop();
|
||||
TweenMax.to(mon,0.6,{"alpha":0});
|
||||
Caller.delayCall(removeChild,1000,1,[mon]);
|
||||
}
|
||||
mon.removeEventListener(MYREvent.REMOVE,removeGroundMonHandler);
|
||||
ArrayUtil.remove(monsters,mon);
|
||||
}
|
||||
|
||||
public function removeGroundMonHandler(e:Event = null) : void
|
||||
{
|
||||
var m:GroundMon = e.target as GroundMon;
|
||||
removeMonster(m);
|
||||
}
|
||||
|
||||
public function resume() : void
|
||||
{
|
||||
for each(var mon:GroundMon in monsters)
|
||||
{
|
||||
mon.resume();
|
||||
}
|
||||
for each(var stack:StackView in stacks)
|
||||
{
|
||||
stack.startOrResume();
|
||||
}
|
||||
EnterFrameDriver.getInstance().regist(step);
|
||||
}
|
||||
|
||||
public function pause() : void
|
||||
{
|
||||
for each(var mon:GroundMon in monsters)
|
||||
{
|
||||
mon.pause();
|
||||
}
|
||||
for each(var stack:StackView in stacks)
|
||||
{
|
||||
stack.pause();
|
||||
}
|
||||
EnterFrameDriver.getInstance().remove(step);
|
||||
}
|
||||
|
||||
public function step() : void
|
||||
{
|
||||
for each(var mon:GroundMon in monsters)
|
||||
{
|
||||
mon.step();
|
||||
for each(var tarmon:GroundMon in monsters)
|
||||
{
|
||||
if(mon.hittestG(tarmon))
|
||||
{
|
||||
mon.hitSomeOne(tarmon);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(sortJump.jump())
|
||||
{
|
||||
Sorter.sortContainerByY(this);
|
||||
}
|
||||
}
|
||||
|
||||
public function gcAllMonster() : void
|
||||
{
|
||||
for each(var m:GroundMon in monsters)
|
||||
{
|
||||
m.dispose();
|
||||
}
|
||||
monsters = [];
|
||||
}
|
||||
|
||||
public function gcAllStackView() : void
|
||||
{
|
||||
if(stacks == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for each(var sv:StackView in stacks)
|
||||
{
|
||||
sv.dispose();
|
||||
}
|
||||
stacks = [];
|
||||
}
|
||||
|
||||
override public function dispose() : void
|
||||
{
|
||||
pause();
|
||||
gcAllMonster();
|
||||
gcAllStackView();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package net.pixvi.myr.panel.ground
|
||||
{
|
||||
import net.pixvi.myr.panel.build.BuildVo;
|
||||
import net.pixvi.pfw.display.PiSprite;
|
||||
|
||||
public class GroundBuildView extends PiSprite
|
||||
{
|
||||
|
||||
public var vo:BuildVo;
|
||||
|
||||
public function GroundBuildView(vo:BuildVo)
|
||||
{
|
||||
this.vo = vo;
|
||||
super();
|
||||
}
|
||||
|
||||
public function buildView() : void
|
||||
{
|
||||
}
|
||||
|
||||
public function updateView() : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user