//building
//  BuildingManager
package com.FengShen.manage.building 
{
    import com.DoGame.DoAlerts.*;
    import com.FengShen.common.*;
    import com.FengShen.data.*;
    import com.FengShen.events.*;
    import com.FengShen.global.*;
    import com.FengShen.manage.*;
    import com.FengShen.net.*;
    import com.FengShen.net.FengShen.*;
    import com.FengShen.protocol.*;
    import com.FengShen.view.base.*;
    import com.FengShen.view.shop.*;
    import flash.events.*;
    
    public class BuildingManager extends Object
    {
        public function BuildingManager(arg1:Object)
        {
            super();
            com.FengShen.manage.LanguageManager.initLanguage(com.FengShen.manage.building.BuildingManager);
            _fs = arg1;
            _instance = this;
            return;
        }

        public function RequestCancelBackoutBuild(arg1:int, arg2:int, arg3:int=-1):void
        {
            arg3 = arg3 < 0 ? com.FengShen.global.GData.currentCityID : arg3;
            com.FengShen.net.FSNetWork.Instance.Send("RequestCancelBackoutBuild", [arg3, arg1, arg2]);
            _fs.doClearFloatPanel();
            return;
        }

        internal function confirmBuy(arg1:*):void
        {
            var loc1:*=new com.FengShen.view.shop.AlertBuyPanelView();
            loc1.setBuyItemID(4901);
            loc1.addEventListener(flash.events.Event.CLOSE, alertMchandler);
            com.DoGame.DoAlerts.Alerts.showFloatMc(loc1);
            return;
        }

        public function RequestBackoutBuild(arg1:int, arg2:int, arg3:int=-1, arg4:Boolean=false):void
        {
            arg3 = arg3 < 0 ? com.FengShen.global.GData.currentCityID : arg3;
            com.FengShen.net.FSNetWork.Instance.Send("RequestBackoutBuild", [arg3, arg1, arg2, arg4]);
            _fs.doClearFloatPanel();
            return;
        }

        internal function alertMchandler(arg1:flash.events.Event):void
        {
            arg1.currentTarget.removeEventListener(flash.events.Event.CLOSE, alertMchandler);
            arg1.currentTarget.gc();
            com.DoGame.DoAlerts.Alerts.clearFloatMc();
            return;
        }

        public function ResponseBackoutBuild(arg1:com.FengShen.events.UltizenEvent):void
        {
            var loc5:*=null;
            trace("服务器返回拆除建造请求信息");
            var loc1:*=arg1.EventObj.result;
            var loc2:*=arg1.EventObj;
            if (loc2 == null || _fs == null) 
            {
                return;
            }
            var loc3:*=(loc3 = (loc3 = Boolean((_fs as com.FengShen.protocol.IFengsheng).currentSence == 0 || (_fs as com.FengShen.protocol.IFengsheng).currentSence == 1)) && Boolean(_fs.FsMapMc)) && !(_fs.FsMapMc is MapAllMod);
            var loc6:*=loc1;
            switch (loc6) 
            {
                case 1:
                {
                    if (loc3 && loc2.cityID == com.FengShen.global.GData.currentCityID) 
                    {
                        _fs.FsMapMc.dealBuilding(loc2);
                    }
                    com.FengShen.view.base.BuildingQueue.getInstance().newBuilding(loc2, loc2.cityID);
                    if (loc2.BuildNamedID == com.FengShen.net.FengShen.EnumNamed.College) 
                    {
                        com.FengShen.common.PublicRequestFunc.getInstance().updateUserTech(loc2.cityID);
                    }
                    break;
                }
                case 3:
                {
                    if (loc3 && loc2.cityID == com.FengShen.global.GData.currentCityID) 
                    {
                        _fs.FsMapMc.dealBuilding(loc2, 1);
                    }
                    com.FengShen.view.base.BuildingQueue.getInstance().completeBuilding(loc2.Position, loc2.cityID);
                    com.FengShen.net.FSNetWork.Instance.Send("RequestGetGenerals", [loc2.cityID]);
                    break;
                }
                case 4:
                {
                    if (loc3 && loc2.cityID == com.FengShen.global.GData.currentCityID) 
                    {
                        _fs.FsMapMc.dealBuilding(loc2, 2);
                    }
                    com.FengShen.view.base.BuildingQueue.getInstance().removeBuilding(loc2.Position, loc2.cityID);
                    break;
                }
                default:
                {
                    if (arg1.EventObj.hasOwnProperty("errCode") && arg1.EventObj.errCode == 1006) 
                    {
                        com.DoGame.DoAlerts.Alerts.showMsg("系统", arg1.EventObj.errMsg, okHandler, true);
                    }
                    else 
                    {
                        com.DoGame.DoAlerts.Alerts.showMsg("系统", arg1.EventObj.errMsg);
                    }
                    break;
                }
            }
            var loc4:*=_fs.floatPanel as com.FengShen.protocol.IBuildingPanel;
            if (!(null == loc4) && loc4.buildPos == loc2.Position) 
            {
                loc5 = com.FengShen.data.BuildingData.getBuildingDetailInfoByPos(loc2.Position);
                loc4.reFreshBuildingata(loc5);
            }
            return;
        }

        public function RequestCancelUpgradeBuild(arg1:int, arg2:int, arg3:int=-1):void
        {
            arg3 = arg3 < 0 ? com.FengShen.global.GData.currentCityID : arg3;
            com.FengShen.net.FSNetWork.Instance.Send("RequestCancelBuildUpgrade", [arg3, arg1, arg2]);
            _fs.doClearFloatPanel();
            return;
        }

        public function RequestBuildUpgrade(arg1:int, arg2:int, arg3:int=-1, arg4:int=1):void
        {
            arg3 = arg3 < 0 ? com.FengShen.global.GData.currentCityID : arg3;
            com.FengShen.net.FSNetWork.Instance.Send("RequestBuildUpgrade", [arg3, arg1, arg2, arg4]);
            _fs.closeFloatPanelMethod();
            return;
        }

        internal function okHandler(arg1:*):void
        {
            if (com.FengShen.data.GoodDatas.getGoodCount(4901) != 0) 
            {
                com.FengShen.net.FSNetWork.Instance.Send("UseBagGoods", [4901, com.FengShen.global.GData.currentCityID]);
            }
            else 
            {
                com.DoGame.DoAlerts.Alerts.showMsg("", com.FengShen.manage.building.BuildingManager.CHAR_PROP, confirmBuy, true);
            }
            return;
        }

        public function ResponseBuildUpgrade(arg1:com.FengShen.events.UltizenEvent):void
        {
            var loc5:*=null;
            var loc1:*=arg1.EventObj.result;
            var loc2:*=arg1.EventObj;
            if (loc2 == null || _fs == null) 
            {
                return;
            }
            var loc3:*=(loc3 = (loc3 = Boolean((_fs as com.FengShen.protocol.IFengsheng).currentSence == 0 || (_fs as com.FengShen.protocol.IFengsheng).currentSence == 1)) && Boolean(_fs.FsMapMc)) && !(_fs.FsMapMc is MapAllMod);
            var loc6:*=loc1;
            switch (loc6) 
            {
                case 1:
                {
                    if (loc3 && loc2.cityID == com.FengShen.global.GData.currentCityID) 
                    {
                        _fs.FsMapMc.dealBuilding(loc2);
                    }
                    com.FengShen.view.base.BuildingQueue.getInstance().newBuilding(loc2, loc2.cityID);
                    break;
                }
                case 3:
                {
                    if (loc3 && loc2.cityID == com.FengShen.global.GData.currentCityID) 
                    {
                        _fs.FsMapMc.dealBuilding(loc2, 1);
                    }
                    com.FengShen.view.base.BuildingQueue.getInstance().completeBuilding(loc2.Position, loc2.cityID);
                    com.FengShen.net.FSNetWork.Instance.Send("RequestGetGenerals", [loc2.cityID]);
                    if (loc2.BuildNamedID == com.FengShen.net.FengShen.EnumNamed.College) 
                    {
                        com.FengShen.common.PublicRequestFunc.getInstance().updateUserTech(loc2.cityID);
                    }
                    break;
                }
                case 4:
                {
                    if (loc3 && loc2.cityID == com.FengShen.global.GData.currentCityID) 
                    {
                        _fs.FsMapMc.dealBuilding(loc2, 2);
                    }
                    com.FengShen.view.base.BuildingQueue.getInstance().removeBuilding(loc2.Position, loc2.cityID);
                    break;
                }
                default:
                {
                    if (arg1.EventObj.hasOwnProperty("errCode") && arg1.EventObj.errCode == 1005) 
                    {
                        com.DoGame.DoAlerts.Alerts.showMsg("系统", arg1.EventObj.errMsg, okHandler, true);
                    }
                    else 
                    {
                        com.DoGame.DoAlerts.Alerts.showMsg("系统", arg1.EventObj.errMsg);
                    }
                    break;
                }
            }
            var loc4:*=_fs.floatPanel as com.FengShen.protocol.IBuildingPanel;
            if (!(null == loc4) && loc4.buildPos == loc2.Position) 
            {
                loc5 = com.FengShen.data.BuildingData.getBuildingDetailInfoByPos(loc2.Position);
                loc4.reFreshBuildingata(loc5);
            }
            return;
        }

        public static function get Instance():com.FengShen.manage.building.BuildingManager
        {
            if (!_instance) 
            {
                throw new Error("has no BuildingManager Instance");
            }
            return _instance;
        }

        internal var _fs:Object;

        internal static var _instance:com.FengShen.manage.building.BuildingManager;

        public static var CHAR_PROP:String;
    }
}


