// Start is called before the first frame update void Awake() { changeRoom = FindObjectOfType <ChangeRoom>(); changeRoom.switchRoom += OnChangeRoom; indexScene = 1; }
IEnumerator Wait(ChangeRoom thisdoor) { yield return(new WaitForSeconds(3)); dadenter = true; daddest = thisdoor.dest; }
private void OnMouseUpAsButton() { if (Gcam.touchable) { if (Gevents.gEvents[10] == 1) { ChangeRoom.chrChangeRoom(); } } }
void OnTriggerEnter2D(Collider2D other) { //if the player collides w/ a door, teleport them to the spawn location of specified destination door if (other.gameObject.tag == "Door") { ChangeRoom thisDoor = other.gameObject.GetComponent <ChangeRoom>(); //get the "ChangeRoom" script of this door if (thisDoor.open == true) { gameObject.transform.position = thisDoor.dest; //teleport player to new destination if (sister_follow == true) { sister.transform.position = thisDoor.dest; } if (dad_chase.dadhome == true) { StartCoroutine(Wait(thisDoor)); } thisCam.roomBounds = thisDoor.roomBounds; thisCam.transform.position = teleportCam(thisDoor); //teleport thisCam to new location, without causing lerp movement //sound fx for doors if (thisDoor.gameObject.name == "BottomDoor") //play key open sound when player use key to open the basement { sound.playSound(SoundEffects.KeyOpen); } else { sound.playSound(SoundEffects.DoorOpen); //play door open sound fx } } else { if (thisDoor.gameObject.name == "BottomDoor") //play key locked sound when player doesn't have key and trying to open the basement { sound.playSound(SoundEffects.KeyLocked); } } } if (inventory.holdingObj != null) { if (other.gameObject.name == "bear_trap_checker" && inventory.holdingObj.name.Contains("BowlingBall")) { spaceToUse.enabled = true; } else if (other.gameObject.name == "PlungeTrigger" && inventory.holdingObj.name.Contains("Plunger")) { spaceToUse.enabled = true; } } }
Vector3 teleportCam(ChangeRoom thisDoor) { //location to teleport the thisCam to the new room without any lerp movement BoxCollider2D roomBounds = thisDoor.roomBounds; float xMin = roomBounds.bounds.min.x; //left float xMax = roomBounds.bounds.max.x; //right float yMin = roomBounds.bounds.min.y; //top float yMax = roomBounds.bounds.max.y; //bottom float camSize = Camera.main.orthographicSize; //half of thisCam height float camRatio = camSize * Camera.main.aspect; //half of thisCam width float camY = Mathf.Clamp(thisDoor.dest.y, yMin + camSize, yMax - camSize); //keep y position inside room bounds float camX = Mathf.Clamp(thisDoor.dest.x, xMin + camRatio, xMax - camRatio); //keep x position inside room bounds return(new Vector3(camX, camY, -10)); //return location }
// Use this for initialization void Awake() { dialogManag = DialogueManager.dialogueManagerInstance; changeRoomInst = this; if (FindObjectsOfType(GetType()).Length > 1) { Destroy(gameObject); } skyboxPositionsList = GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer skyB in skyboxPositionsList) { skyB.gameObject.SetActive(false); } skyboxPositionsList[0].gameObject.SetActive(true); blackScreen = PlayerManager.playerManagerInst.blackScreen; }
private void FixedUpdate() { switch (wasActive) { //******************************************************************************************************** case 5: Ggos.g.goTv101.SetActive(false); Ggos.g.goTv11.SetActive(true); wasActive = 0; break; //******************************************************************************************************** case 10: if (count == 0) { angleTemp = new Vector3(0f, 0f, 0f); Gcam.touchable = false; Ggos.g.goDoor1key1.SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[8]); } if (count > 19) { angleTemp.z += 12; Ggos.g.goDoor1keyhole.transform.localEulerAngles = angleTemp; } if (count == 50) { Gcam.myLoc = 0; Ggos.g.goDoor1keyholeplate.GetComponent <BoxCollider>().enabled = false; Ggos.g.goDoor1.GetComponent <BoxCollider>().enabled = true; ChangeRoom.chrChangeRoom(); } count++; if (count > 50) { count = 0; wasActive = 0; } break; //******************************************************************************************************** case 14: if (count == 0) { Gcam.touchable = false; } if (count == 10) { Ggos.g.goWrenchdrivers1[0].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); angleTemp = new Vector3(0f, 0f, 330f); } if (count > 10 && count < 30) { angleTemp.z -= 2; Ggos.g.goVentilation1bolts[0].transform.localEulerAngles = angleTemp; } if (count == 30) { Ggos.g.goVentilation1bolts[0].SetActive(false); } if (count == 60) { Ggos.g.goWrenchdrivers1[1].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); angleTemp = new Vector3(0f, 0f, 0f); } if (count > 60 && count < 80) { angleTemp.z -= 2; Ggos.g.goVentilation1bolts[1].transform.localEulerAngles = angleTemp; } if (count == 80) { Ggos.g.goVentilation1bolts[1].SetActive(false); } if (count == 110) { Ggos.g.goWrenchdrivers1[2].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); angleTemp = new Vector3(0f, 0f, 0f); } if (count > 110 && count < 130) { angleTemp.z -= 2; Ggos.g.goVentilation1bolts[2].transform.localEulerAngles = angleTemp; } if (count == 130) { Ggos.g.goVentilation1bolts[2].SetActive(false); } if (count == 160) { Ggos.g.goWrenchdrivers1[3].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); angleTemp = new Vector3(0f, 0f, 330f); } if (count > 160 && count < 180) { angleTemp.z -= 2; Ggos.g.goVentilation1bolts[3].transform.localEulerAngles = angleTemp; } if (count == 180) { Ggos.g.goVentilation1bolts[3].SetActive(false); } if (count == 210) { Ggos.g.goVentilation1grid.SetActive(false); } if (count == 240) { Gcam.ChangeLocation(15); } count++; if (count > 240) { count = 0; wasActive = 0; } break; //******************************************************************************************************** case 16: if (count == 0) { angleTemp = new Vector3(0f, 0f, 0f); Gcam.touchable = false; Ggos.g.goBureau1key2.SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[8]); } if (count > 19) { angleTemp.z += 12; Ggos.g.goBureau1keyhole2.transform.localEulerAngles = angleTemp; } count++; if (count > 49) { Gcam.touchable = true; count = 0; wasActive = 0; } break; //******************************************************************************************************** case 18: Ggos.g.goPic4pieces[3].SetActive(true); Ggos.g.goPic4P.GetComponent <BoxCollider>().enabled = false; for (int i = 0; i < 9; i++) { Ggos.g.goPic4pieces[i].GetComponent <BoxCollider>().enabled = true; } Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[4]); wasActive = 0; break; //******************************************************************************************************** case 23: if (count == 0) { Gcam.touchable = false; rotTemp = Quaternion.AngleAxis(10f, Vector3.forward); } if (count == 10) { Ggos.g.goScrewdrivers1[0].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); } if (count > 10 && count < 30) { Ggos.g.goSp1screws[0].transform.localRotation *= rotTemp; } if (count == 30) { Ggos.g.goSp1screws[0].SetActive(false); } if (count == 60) { Ggos.g.goScrewdrivers1[1].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); } if (count > 60 && count < 80) { Ggos.g.goSp1screws[1].transform.localRotation *= rotTemp; } if (count == 80) { Ggos.g.goSp1screws[1].SetActive(false); } if (count == 110) { Ggos.g.goScrewdrivers1[2].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); } if (count > 110 && count < 130) { Ggos.g.goSp1screws[2].transform.localRotation *= rotTemp; } if (count == 130) { Ggos.g.goSp1screws[2].SetActive(false); } if (count == 160) { Ggos.g.goScrewdrivers1[3].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); } if (count > 160 && count < 180) { Ggos.g.goSp1screws[3].transform.localRotation *= rotTemp; } if (count == 180) { Ggos.g.goSp1screws[3].SetActive(false); } if (count == 210) { Ggos.g.goSp1door.SetActive(false); } count++; if (count > 210) { Ggos.g.goSp1pin2.GetComponent <BoxCollider>().enabled = true; Gcam.touchable = true; count = 0; wasActive = 0; } break; //******************************************************************************************************** case 24: if (count == 0) { Gcam.touchable = false; rotTemp = Quaternion.AngleAxis(10f, Vector3.forward); } if (count == 10) { Ggos.g.goScrewdrivers2[0].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); } if (count > 10 && count < 30) { Ggos.g.goSp2screws[0].transform.localRotation *= rotTemp; } if (count == 30) { Ggos.g.goSp2screws[0].SetActive(false); } if (count == 60) { Ggos.g.goScrewdrivers2[1].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); } if (count > 60 && count < 80) { Ggos.g.goSp2screws[1].transform.localRotation *= rotTemp; } if (count == 80) { Ggos.g.goSp2screws[1].SetActive(false); } if (count == 110) { Ggos.g.goScrewdrivers2[2].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); } if (count > 110 && count < 130) { Ggos.g.goSp2screws[2].transform.localRotation *= rotTemp; } if (count == 130) { Ggos.g.goSp2screws[2].SetActive(false); } if (count == 160) { Ggos.g.goScrewdrivers2[3].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); } if (count > 160 && count < 180) { Ggos.g.goSp2screws[3].transform.localRotation *= rotTemp; } if (count == 180) { Ggos.g.goSp2screws[3].SetActive(false); } if (count == 210) { Ggos.g.goSp2door.SetActive(false); } count++; if (count > 210) { Ggos.g.goSp2pin1.GetComponent <BoxCollider>().enabled = true; Gcam.touchable = true; count = 0; wasActive = 0; } break; //******************************************************************************************************** case 28: if (count == 0) { Ggos.g.goSp1cogwheels[2].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[5]); if (Gevents.gEvents[29] == 1 && Gevents.gEvents[32] == 1) { Gevents.WasEvent(33); Gcam.touchable = false; } else { count = -1; wasActive = 0; } } if (count == 29) { Ggos.g.goMainCamera.transform.localPosition = Gcam.camPos[29]; Ggos.g.goMainCamera.transform.localEulerAngles = Gcam.camRot[29]; } if (count > 29 && count < 80) { angleTemp = Ggos.g.goPic2indoor1.transform.localPosition; angleTemp.x -= 0.002f; Ggos.g.goPic2indoor1.transform.localPosition = angleTemp; angleTemp = Ggos.g.goPic2indoor2.transform.localPosition; angleTemp.x += 0.002f; Ggos.g.goPic2indoor2.transform.localPosition = angleTemp; } count++; if (count >= 110) { Ggos.g.goMainCamera.transform.localPosition = Gcam.camPos[23]; Ggos.g.goMainCamera.transform.localEulerAngles = Gcam.camRot[23]; Gcam.touchable = true; count = 0; wasActive = 0; } break; //******************************************************************************************************** case 29: if (count == 0) { Ggos.g.goSp2cogwheels[1].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[5]); if (Gevents.gEvents[28] == 1 && Gevents.gEvents[32] == 1) { Gevents.WasEvent(33); Gcam.touchable = false; } else { count = -1; wasActive = 0; } } if (count == 29) { Ggos.g.goMainCamera.transform.localPosition = Gcam.camPos[29]; Ggos.g.goMainCamera.transform.localEulerAngles = Gcam.camRot[29]; } if (count > 29 && count < 80) { angleTemp = Ggos.g.goPic2indoor1.transform.localPosition; angleTemp.x -= 0.002f; Ggos.g.goPic2indoor1.transform.localPosition = angleTemp; angleTemp = Ggos.g.goPic2indoor2.transform.localPosition; angleTemp.x += 0.002f; Ggos.g.goPic2indoor2.transform.localPosition = angleTemp; } count++; if (count >= 110) { Ggos.g.goMainCamera.transform.localPosition = Gcam.camPos[24]; Ggos.g.goMainCamera.transform.localEulerAngles = Gcam.camRot[24]; Gcam.touchable = true; count = 0; wasActive = 0; } break; //******************************************************************************************************** case 31: Ggos.g.goPic2pieces[7].SetActive(true); Ggos.g.goPic2in.GetComponent <BoxCollider>().enabled = false; for (int i = 0; i < 9; i++) { Ggos.g.goPic2pieces[i].GetComponent <BoxCollider>().enabled = true; } Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[4]); wasActive = 0; break; //******************************************************************************************************** case 35: Ggos.g.goPic1pieces[6].SetActive(true); Ggos.g.goPic1in.GetComponent <BoxCollider>().enabled = false; for (int i = 0; i < 9; i++) { Ggos.g.goPic1pieces[i].GetComponent <BoxCollider>().enabled = true; } Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[4]); wasActive = 0; break; //******************************************************************************************************** case 37: if (count == 0) { Gcam.touchable = false; } if (count == 10) { Ggos.g.goWrenchdrivers2[0].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); angleTemp = new Vector3(0f, 0f, 330f); } if (count > 10 && count < 30) { angleTemp.z -= 2; Ggos.g.goVentilation2bolts[0].transform.localEulerAngles = angleTemp; } if (count == 30) { Ggos.g.goVentilation2bolts[0].SetActive(false); } if (count == 60) { Ggos.g.goWrenchdrivers2[1].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); angleTemp = new Vector3(0f, 0f, 0f); } if (count > 60 && count < 80) { angleTemp.z -= 2; Ggos.g.goVentilation2bolts[1].transform.localEulerAngles = angleTemp; } if (count == 80) { Ggos.g.goVentilation2bolts[1].SetActive(false); } if (count == 110) { Ggos.g.goWrenchdrivers2[2].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); angleTemp = new Vector3(0f, 0f, 0f); } if (count > 110 && count < 130) { angleTemp.z -= 2; Ggos.g.goVentilation2bolts[2].transform.localEulerAngles = angleTemp; } if (count == 130) { Ggos.g.goVentilation2bolts[2].SetActive(false); } if (count == 160) { Ggos.g.goWrenchdrivers2[3].SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[9]); angleTemp = new Vector3(0f, 0f, 330f); } if (count > 160 && count < 180) { angleTemp.z -= 2; Ggos.g.goVentilation2bolts[3].transform.localEulerAngles = angleTemp; } if (count == 180) { Ggos.g.goVentilation2bolts[3].SetActive(false); } if (count == 210) { Ggos.g.goVentilation2grid.SetActive(false); } if (count == 240) { Gcam.ChangeLocation(34); } count++; if (count > 240) { count = 0; wasActive = 0; } break; //******************************************************************************************************** case 39: Ggos.g.goPic3pieces[8].SetActive(true); Ggos.g.goPic3in.GetComponent <BoxCollider>().enabled = false; for (int i = 0; i < 9; i++) { Ggos.g.goPic3pieces[i].GetComponent <BoxCollider>().enabled = true; } Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[4]); wasActive = 0; break; //******************************************************************************************************** case 42: if (count == 0) { Ggos.g.goPic2key1.SetActive(true); Ggos.g.goPic2keyhole.GetComponent <BoxCollider>().enabled = false; Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[4]); if (Gevents.gEvents[36] == 1 && Gevents.gEvents[40] == 1) { Gevents.WasEvent(43); Gevents.WasEvent(44); Gcam.touchable = false; } else { count = -1; wasActive = 0; } } if (count == 29) { Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[6]); } if (count > 29 && count < 55) { angleTemp = Ggos.g.goPic2key1.transform.localEulerAngles; angleTemp.z -= 3.6f; Ggos.g.goPic2key1.transform.localEulerAngles = angleTemp; } if (count == 55) { Ggos.g.goMainCamera.transform.localPosition = Gcam.camPos[31]; Ggos.g.goMainCamera.transform.localEulerAngles = Gcam.camRot[31]; } if (count > 54 && count < 80) { angleTemp = Ggos.g.goPic1indoor1.transform.localPosition; angleTemp.x -= 0.004f; Ggos.g.goPic1indoor1.transform.localPosition = angleTemp; angleTemp = Ggos.g.goPic1indoor2.transform.localPosition; angleTemp.x += 0.004f; Ggos.g.goPic1indoor2.transform.localPosition = angleTemp; } if (count == 80) { Ggos.g.goMainCamera.transform.localPosition = Gcam.camPos[35]; Ggos.g.goMainCamera.transform.localEulerAngles = Gcam.camRot[35]; } if (count > 79 && count < 105) { angleTemp = Ggos.g.goPic3indoor1.transform.localPosition; angleTemp.x -= 0.004f; Ggos.g.goPic3indoor1.transform.localPosition = angleTemp; angleTemp = Ggos.g.goPic3indoor2.transform.localPosition; angleTemp.x += 0.004f; Ggos.g.goPic3indoor2.transform.localPosition = angleTemp; } if (count == 105) { Ggos.g.goMainCamera.transform.localPosition = Gcam.camPos[30]; Ggos.g.goMainCamera.transform.localEulerAngles = Gcam.camRot[30]; } if (count > 104 && count < 130) { angleTemp = Ggos.g.goPic2key1.transform.localEulerAngles; angleTemp.z -= 3.6f; Ggos.g.goPic2key1.transform.localEulerAngles = angleTemp; } count++; if (count >= 130) { Gcam.touchable = true; count = 0; wasActive = 0; } break; //******************************************************************************************************** case 46: if (count == 0) { Gcam.touchable = false; Ggos.g.goPic1coin1.SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[3]); } if (count == 29) { Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[6]); } if (count > 29 && count < 130) { angleTemp = Ggos.g.goPic1btnspanel.transform.localEulerAngles; angleTemp.y += 1.8f; Ggos.g.goPic1btnspanel.transform.localEulerAngles = angleTemp; angleTemp = Ggos.g.goPic1coinsocket.transform.localEulerAngles; angleTemp.z += 3.6f; Ggos.g.goPic1coinsocket.transform.localEulerAngles = angleTemp; } count++; if (count >= 130) { Ggos.g.goPic1coinsocket.GetComponent <BoxCollider>().enabled = false; for (int i = 0; i < Ggos.g.goPic1btns.Length; i++) { Ggos.g.goPic1btns[i].GetComponent <BoxCollider>().enabled = true; } Gcam.touchable = true; count = 0; wasActive = 0; } break; //******************************************************************************************************** case 48: if (count == 0) { Gcam.touchable = false; Ggos.g.goPic3coin1.SetActive(true); Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[3]); } if (count == 29) { Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[6]); } if (count > 29 && count < 130) { angleTemp = Ggos.g.goPic3btnspanel.transform.localEulerAngles; angleTemp.y += 1.8f; Ggos.g.goPic3btnspanel.transform.localEulerAngles = angleTemp; angleTemp = Ggos.g.goPic3coinsocket.transform.localEulerAngles; angleTemp.z += 3.6f; Ggos.g.goPic3coinsocket.transform.localEulerAngles = angleTemp; } count++; if (count >= 130) { Ggos.g.goPic3coinsocket.GetComponent <BoxCollider>().enabled = false; for (int i = 0; i < Ggos.g.goPic3btns.Length; i++) { Ggos.g.goPic3btns[i].GetComponent <BoxCollider>().enabled = true; } Gcam.touchable = true; count = 0; wasActive = 0; } break; //******************************************************************************************************** case 50: Ggos.g.goNotebook1flash1.SetActive(true); matTemp = Ggos.g.goNotebook1.GetComponent <MeshRenderer>().materials; matTemp[1] = Ggos.g.mats[5]; Ggos.g.goNotebook1.GetComponent <MeshRenderer>().materials = matTemp; Ggos.g.goNotebook1.GetComponent <BoxCollider>().enabled = false; Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[4]); wasActive = 0; break; //******************************************************************************************************** default: wasActive = 0; break; } switch (wasnotActive) { //******************************************************************************************************** case 10: if (count == 0) { angleTemp = new Vector3(0f, 0f, 0f); Gcam.touchable = false; Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[1]); } if (count < 8) { angleTemp.z += 3; Ggos.g.goDoor1handle.transform.localEulerAngles = angleTemp; } if (count >= 8) { angleTemp.z -= 3; Ggos.g.goDoor1handle.transform.localEulerAngles = angleTemp; } count++; if (count > 15) { Gcam.touchable = true; count = 0; wasnotActive = 0; } break; //******************************************************************************************************** case 16: Ggos.g.goMainCamera.GetComponent <AudioSource>().PlayOneShot(Ggos.g.audioClips[1]); wasnotActive = 0; break; //******************************************************************************************************** default: wasnotActive = 0; break; } }
void Spawn(DudeAnimationInfo LoadedCharacter, Scene.Document LoadedScene) { var ViewSize = new Size { Width = 640, Height = 480 }; var Container = new IHTMLDiv(); Container.AttachToDocument(); Container.style.SetSize(ViewSize.Width, ViewSize.Height + 22); Container.KeepInCenter(); //Container.MakeCSSShaderCrumple(); var Wallpaper = new IHTMLDiv().AttachTo(Container); Wallpaper.style.SetSize(ViewSize.Width, ViewSize.Height + 22); new power().ToBackground(Wallpaper.style); Wallpaper.style.position = IStyle.PositionEnum.absolute; Wallpaper.style.backgroundRepeat = "no-repeat"; Wallpaper.style.backgroundPosition = "center center"; var Margin = 48; var MarginSafe = 72; var CurrentFrame = LoadedScene.Frames.Randomize().First(); //var CurrentFrame = LoadedScene.Frames.Single(f => f.Name == "C"); var Room = new IHTMLDiv(); Room.style.border = "1px solid #00ff00"; Room.style.SetSize(ViewSize.Width, ViewSize.Height); Room.style.position = IStyle.PositionEnum.absolute; Room.style.overflow = IStyle.OverflowEnum.hidden; Room.AttachTo(Container); Room.style.SetLocation(0, 22); //Room.AttachToDocument(); //Room.KeepInCenter(); var tween = Room.ToOpacityTween(); Action HideRoom = () => tween.Value = 1; Action ShowRoom = () => tween.Value = 0; HideRoom(); //var GroundOverlay2 = new IHTMLDiv(); //GroundOverlay2.style.backgroundColor = Color.Blue; ////GroundOverlay.style.Opacity = 0; //GroundOverlay2.style.position = IStyle.PositionEnum.absolute; //GroundOverlay2.style.SetLocation(0, 0, ViewSize.Width, ViewSize.Height); //GroundOverlay2.AttachTo(Room); var LostInTime_Images = new ImpAdventures.HTML.Pages.LostInTimeImages().Images; var BackgroundImage = new IHTMLImage(); LostInTime_Images.FirstOrDefault( k => k.src.SkipUntilLastIfAny("/") == CurrentFrame.Image.Source.SkipUntilLastIfAny("/") ).With( ImageSource => { Console.WriteLine(ImageSource.src); BackgroundImage.src = ImageSource.src; } ); BackgroundImage.style.SetLocation(0, 0, ViewSize.Width, ViewSize.Height); BackgroundImage.alt = "BackgroundImage"; BackgroundImage.AttachTo(Room); //GroundOverlay2.style.backgroundImage = "url(" + CurrentFrame.Image.Source + ")"; //BackgroundImage.InvokeOnComplete( // delegate // { // //BackgroundImage.style.backgroundColor = Color.Red; // //BackgroundImage.style.SetLocation(0,0, ViewSize.Width, ViewSize.Height); // BackgroundImage.AttachTo(GroundOverlay2); // } //); var GroundOverlay = new IHTMLDiv(); GroundOverlay.style.backgroundColor = Color.Blue; GroundOverlay.style.Opacity = 0; GroundOverlay.style.SetLocation(0, 0, ViewSize.Width, ViewSize.Height); GroundOverlay.AttachTo(Room); var Ground = new IHTMLDiv(); Ground.style.SetLocation(0, 0, ViewSize.Width, ViewSize.Height); Ground.AttachTo(Room); var AnimateRoomChange = default(Action <Action>); #region TryToChangeRooms Func <TryToChangeRoomsArgs, bool> TryToChangeRooms = e => { if (e == null) { return(false); } if (e.NextRoomSelector == null) { throw new ArgumentNullException("NextRoomSelector"); } var next = LoadedScene.Frames.SingleOrDefault(e.NextRoomSelector); var r = next != null; if (r) { AnimateRoomChange( delegate { CurrentFrame = next; Console.WriteLine("AnimateRoomChange"); LostInTime_Images.FirstOrDefault( k => k.src.SkipUntilLastIfAny("/") == CurrentFrame.Image.Source.SkipUntilLastIfAny("/") ).With( ImageSource => { Console.WriteLine(ImageSource.src); BackgroundImage.src = ImageSource.src; } ); //GroundOverlay2.style.backgroundImage = "url(" + CurrentFrame.Image.Source + ")"; //BackgroundImage.src = CurrentFrame.Image.Source; e.ReadyToTeleport(); } ); } return(r); }; #endregion var dude = CreateDude(LoadedCharacter); dude.Control.AttachTo(Ground); #region Doors var Doors = new[] { new TryToChangeRoomsArgs { Condition = () => dude.CurrentLocation.X > ViewSize.Width - Margin, NextRoomSelector = f => f.Name == CurrentFrame.Right, ReadyToTeleport = delegate { dude.TeleportTo(-MarginSafe, dude.CurrentLocation.Y); dude.LookAt(new Point(MarginSafe, (int)dude.CurrentLocation.Y)); } }, new TryToChangeRoomsArgs { Condition = () => dude.CurrentLocation.X < Margin, NextRoomSelector = f => f.Name == CurrentFrame.Left, ReadyToTeleport = delegate { dude.TeleportTo(ViewSize.Width + MarginSafe, dude.CurrentLocation.Y); dude.LookAt(new Point(ViewSize.Width - MarginSafe, (int)dude.CurrentLocation.Y)); } }, new TryToChangeRoomsArgs { Condition = () => dude.CurrentLocation.Y < Margin, NextRoomSelector = f => f.Name == CurrentFrame.Top, ReadyToTeleport = delegate { dude.TeleportTo(dude.CurrentLocation.X, ViewSize.Height + MarginSafe); dude.LookAt(new Point((int)dude.CurrentLocation.X, ViewSize.Height - MarginSafe)); } }, new TryToChangeRoomsArgs { Condition = () => dude.CurrentLocation.Y > ViewSize.Height - Margin, NextRoomSelector = f => f.Name == CurrentFrame.Bottom, ReadyToTeleport = delegate { dude.TeleportTo(dude.CurrentLocation.X, -Margin); dude.LookAt(new Point((int)dude.CurrentLocation.X, MarginSafe)); } } }; #endregion Console.WriteLine(new { Doors = Doors.Length }); Doors.WithEachIndex( (x, index) => { Console.WriteLine(new { index, x }); Console.WriteLine(new { index, x.Condition }); } ); var ChangeRoom = new ChangeRoom { autobuffer = true }; var Talk = new Talk { autobuffer = true }; var Argh_RChannel = new Argh_RChannel { autobuffer = true }; var Argh_LChannel = new Argh_LChannel { autobuffer = true }; var Argh_Disabled = false; var Argh_VolumeMultiplier = 1.0; #region Argh_Stereo Action <double, double> Argh_Stereo = (volume, balance) => { if (Argh_Disabled) { return; } Argh_RChannel.AttachToDocument(); Argh_LChannel.AttachToDocument(); Argh_RChannel.volume = Argh_VolumeMultiplier * volume * balance; Argh_LChannel.volume = Argh_VolumeMultiplier * volume * (1 - balance); Argh_RChannel.play(); Argh_LChannel.play(); Argh_RChannel = new Argh_RChannel { autobuffer = true }; Argh_LChannel = new Argh_LChannel { autobuffer = true }; Argh_Disabled = true; Argh_VolumeMultiplier /= 2; new Timer(t => Argh_Disabled = false).StartTimeout(800); new Timer(t => Argh_VolumeMultiplier = 1).StartTimeout(5000); }; #endregion #region PrintText Action <string, Action> PrintText = (text, done) => { Talk.AttachToDocument(); Talk.load(); Talk.volume = Math.Min(1, dude.Zoom.DynamicZoom / 4); Talk.play(); Talk = new Talk { autobuffer = true }; text.Length.Range().AsyncForEach( i => { Wallpaper.innerText = text.Left(i + 1); var c = text[i]; if (LoadedScene.SlowText.Contains("" + c)) { return(100.Random()); } return(50.Random()); }, done ); }; #endregion Action <string, Action> PrintRandomText = (text, done) => PrintText(text.Split(LoadedScene.TextDelimiter).Randomize().First(), done); dude.DoneWalking += delegate { // compiler bug: cannot invoke Action<func, action> delegate ? System.Console.WriteLine("done walking in " + CurrentFrame.Name + " at " + dude.CurrentLocation); var xFirstOrDefault = Doors.FirstOrDefault(d => d.Condition()); System.Console.WriteLine("done walking in " + new { xFirstOrDefault }); // Doors null? if (TryToChangeRooms(xFirstOrDefault)) { return; } if (CurrentFrame.Items != null) { var item = CurrentFrame.Items.Where( i => new Point(i.X.ToInt32(), i.Y.ToInt32()).GetRange(dude.CurrentLocation) < i.R.ToInt32() ).FirstOrDefault(); if (item != null) { dude.IsSelected = false; dude.LookDown(); PrintRandomText(item.Text, delegate { dude.WalkingOnce += delegate { Wallpaper.innerText = ""; }; dude.IsSelected = true; } ); } } }; #region AnimateRoomChange AnimateRoomChange = ReadyToTeleport => { var Step1 = default(System.Action); var Step2 = default(System.Action); var Step3 = default(Action); Step1 = delegate { tween.Done -= Step1; ReadyToTeleport(); tween.Done += Step2; ShowRoom(); }; Step2 = delegate { tween.Done -= Step2; dude.DoneWalking += Step3; dude.IsWalking = true; }; Step3 = delegate { dude.DoneWalking -= Step3; dude.IsSelected = true; }; dude.IsSelected = false; tween.Done += Step1; // go left HideRoom(); // http://stackoverflow.com/questions/3009888/autoplay-audio-files-on-an-ipad-with-html5 ChangeRoom.AttachToDocument(); ChangeRoom.load(); ChangeRoom.volume = 0.2; ChangeRoom.play(); ChangeRoom = new ChangeRoom(); }; #endregion var pointer_x = 0; var pointer_y = 0; #region onmousemove Container.onmousemove += ev => { if (Native.Document.pointerLockElement == Container) { if (dude.IsSelected) { var volume = Math.Min(1, dude.Zoom.DynamicZoom / 4); var balance = dude.CurrentLocation.X / ViewSize.Width; pointer_x += ev.movementX; pointer_y += ev.movementY; pointer_x = Math.Min(ViewSize.Width - 0, Math.Max(0, pointer_x)); pointer_y = Math.Min(ViewSize.Height - 0, Math.Max(0, pointer_y)); var OffsetPosition = new Point(pointer_x, pointer_y ); Console.WriteLine(OffsetPosition); Argh_Stereo(volume, balance); dude.WalkTo(OffsetPosition); } } }; #endregion #region ontouchstart Container.ontouchstart += ev => { ev.PreventDefault(); System.Console.WriteLine(ev.CursorPosition); if (dude.IsSelected) { var volume = Math.Min(1, dude.Zoom.DynamicZoom / 4); var balance = dude.CurrentLocation.X / ViewSize.Width; var ev_OffsetPosition = new Point( ev.touches[0].clientX - Container.Bounds.Left, ev.touches[0].clientY - Container.Bounds.Top ); Argh_Stereo(volume, balance); dude.WalkTo(ev_OffsetPosition); } }; #endregion #region onclick Container.onclick += ev => { ev.PreventDefault(); if (ev.MouseButton == IEvent.MouseButtonEnum.Middle) { if (Native.Document.pointerLockElement == Container) { Native.Document.exitPointerLock(); return; } pointer_x = (int)dude.CurrentLocation.X; pointer_y = (int)dude.CurrentLocation.Y; //Container.requestFullscreen(); Container.requestPointerLock(); return; } if (ev.Element != Ground) { return; } System.Console.WriteLine(ev.CursorPosition); if (dude.IsSelected) { var volume = Math.Min(1, dude.Zoom.DynamicZoom / 4); var balance = dude.CurrentLocation.X / ViewSize.Width; Argh_Stereo(volume, balance); dude.WalkTo(ev.OffsetPosition); } }; #endregion //GroundOverlay.onclick += // ev => // { // if (ev.Element != GroundOverlay) // return; // System.Console.WriteLine(ev.CursorPosition); // if (dude.IsSelected) // { // new Argh().play(); // dude.WalkTo(ev.OffsetPosition); // } // }; dude.TeleportTo(ViewSize.Width / 2, (ViewSize.Height - MarginSafe) / 2); dude.LookDown(); ShowRoom(); dude.DoneWalkingOnce += delegate { PrintRandomText( LoadedScene.IntroText, delegate { dude.WalkingOnce += delegate { Wallpaper.innerText = ""; }; dude.IsSelected = true; } ); }; dude.WalkToArc(MarginSafe, dude.Direction); }
void Spawn(DudeAnimationInfo LoadedCharacter, Scene.Document LoadedScene) { var ViewSize = new Size { Width = 640, Height = 480 }; var Container = new IHTMLDiv(); Container.AttachToDocument(); Container.style.SetSize(ViewSize.Width, ViewSize.Height + 22); Container.KeepInCenter(); //Container.MakeCSSShaderCrumple(); var Wallpaper = new IHTMLDiv().AttachTo(Container); Wallpaper.style.SetSize(ViewSize.Width, ViewSize.Height + 22); new power().ToBackground(Wallpaper.style); Wallpaper.style.position = IStyle.PositionEnum.absolute; Wallpaper.style.backgroundRepeat = "no-repeat"; Wallpaper.style.backgroundPosition = "center center"; var Margin = 48; var MarginSafe = 72; var CurrentFrame = LoadedScene.Frames.Randomize().First(); //var CurrentFrame = LoadedScene.Frames.Single(f => f.Name == "C"); var Room = new IHTMLDiv(); Room.style.border = "1px solid #00ff00"; Room.style.SetSize(ViewSize.Width, ViewSize.Height); Room.style.position = IStyle.PositionEnum.absolute; Room.style.overflow = IStyle.OverflowEnum.hidden; Room.AttachTo(Container); Room.style.SetLocation(0, 22); //Room.AttachToDocument(); //Room.KeepInCenter(); var tween = Room.ToOpacityTween(); Action HideRoom = () => tween.Value = 1; Action ShowRoom = () => tween.Value = 0; HideRoom(); //var GroundOverlay2 = new IHTMLDiv(); //GroundOverlay2.style.backgroundColor = Color.Blue; ////GroundOverlay.style.Opacity = 0; //GroundOverlay2.style.position = IStyle.PositionEnum.absolute; //GroundOverlay2.style.SetLocation(0, 0, ViewSize.Width, ViewSize.Height); //GroundOverlay2.AttachTo(Room); var LostInTime_Images = new ImpAdventures.HTML.Pages.LostInTimeImages().Images; var BackgroundImage = new IHTMLImage(); LostInTime_Images.FirstOrDefault( k => k.src.SkipUntilLastIfAny("/") == CurrentFrame.Image.Source.SkipUntilLastIfAny("/") ).With( ImageSource => { Console.WriteLine(ImageSource.src); BackgroundImage.src = ImageSource.src; } ); BackgroundImage.style.SetLocation(0, 0, ViewSize.Width, ViewSize.Height); BackgroundImage.alt = "BackgroundImage"; BackgroundImage.AttachTo(Room); //GroundOverlay2.style.backgroundImage = "url(" + CurrentFrame.Image.Source + ")"; //BackgroundImage.InvokeOnComplete( // delegate // { // //BackgroundImage.style.backgroundColor = Color.Red; // //BackgroundImage.style.SetLocation(0,0, ViewSize.Width, ViewSize.Height); // BackgroundImage.AttachTo(GroundOverlay2); // } //); var GroundOverlay = new IHTMLDiv(); GroundOverlay.style.backgroundColor = Color.Blue; GroundOverlay.style.Opacity = 0; GroundOverlay.style.SetLocation(0, 0, ViewSize.Width, ViewSize.Height); GroundOverlay.AttachTo(Room); var Ground = new IHTMLDiv(); Ground.style.SetLocation(0, 0, ViewSize.Width, ViewSize.Height); Ground.AttachTo(Room); var AnimateRoomChange = default(Action<Action>); #region TryToChangeRooms Func<TryToChangeRoomsArgs, bool> TryToChangeRooms = e => { if (e == null) return false; if (e.NextRoomSelector == null) throw new ArgumentNullException("NextRoomSelector"); var next = LoadedScene.Frames.SingleOrDefault(e.NextRoomSelector); var r = next != null; if (r) { AnimateRoomChange( delegate { CurrentFrame = next; Console.WriteLine("AnimateRoomChange"); LostInTime_Images.FirstOrDefault( k => k.src.SkipUntilLastIfAny("/") == CurrentFrame.Image.Source.SkipUntilLastIfAny("/") ).With( ImageSource => { Console.WriteLine(ImageSource.src); BackgroundImage.src = ImageSource.src; } ); //GroundOverlay2.style.backgroundImage = "url(" + CurrentFrame.Image.Source + ")"; //BackgroundImage.src = CurrentFrame.Image.Source; e.ReadyToTeleport(); } ); } return r; }; #endregion var dude = CreateDude(LoadedCharacter); dude.Control.AttachTo(Ground); #region Doors var Doors = new[] { new TryToChangeRoomsArgs { Condition = () => dude.CurrentLocation.X > ViewSize.Width - Margin, NextRoomSelector = f => f.Name == CurrentFrame.Right, ReadyToTeleport = delegate { dude.TeleportTo(-MarginSafe, dude.CurrentLocation.Y); dude.LookAt(new Point(MarginSafe, (int)dude.CurrentLocation.Y)); } }, new TryToChangeRoomsArgs { Condition = () => dude.CurrentLocation.X < Margin, NextRoomSelector = f => f.Name == CurrentFrame.Left, ReadyToTeleport = delegate { dude.TeleportTo(ViewSize.Width + MarginSafe, dude.CurrentLocation.Y); dude.LookAt(new Point(ViewSize.Width - MarginSafe, (int)dude.CurrentLocation.Y)); } }, new TryToChangeRoomsArgs { Condition = () => dude.CurrentLocation.Y < Margin, NextRoomSelector = f => f.Name == CurrentFrame.Top, ReadyToTeleport = delegate { dude.TeleportTo(dude.CurrentLocation.X, ViewSize.Height + MarginSafe); dude.LookAt(new Point((int)dude.CurrentLocation.X, ViewSize.Height - MarginSafe)); } }, new TryToChangeRoomsArgs { Condition = () => dude.CurrentLocation.Y > ViewSize.Height - Margin, NextRoomSelector = f => f.Name == CurrentFrame.Bottom, ReadyToTeleport = delegate { dude.TeleportTo(dude.CurrentLocation.X, -Margin); dude.LookAt(new Point((int)dude.CurrentLocation.X, MarginSafe)); } } }; #endregion Console.WriteLine(new { Doors = Doors.Length }); Doors.WithEachIndex( (x, index) => { Console.WriteLine(new { index, x }); Console.WriteLine(new { index, x.Condition }); } ); var ChangeRoom = new ChangeRoom { autobuffer = true }; var Talk = new Talk { autobuffer = true }; var Argh_RChannel = new Argh_RChannel { autobuffer = true }; var Argh_LChannel = new Argh_LChannel { autobuffer = true }; var Argh_Disabled = false; var Argh_VolumeMultiplier = 1.0; #region Argh_Stereo Action<double, double> Argh_Stereo = (volume, balance) => { if (Argh_Disabled) return; Argh_RChannel.AttachToDocument(); Argh_LChannel.AttachToDocument(); Argh_RChannel.volume = Argh_VolumeMultiplier * volume * balance; Argh_LChannel.volume = Argh_VolumeMultiplier * volume * (1 - balance); Argh_RChannel.play(); Argh_LChannel.play(); Argh_RChannel = new Argh_RChannel { autobuffer = true }; Argh_LChannel = new Argh_LChannel { autobuffer = true }; Argh_Disabled = true; Argh_VolumeMultiplier /= 2; new Timer(t => Argh_Disabled = false).StartTimeout(800); new Timer(t => Argh_VolumeMultiplier = 1).StartTimeout(5000); }; #endregion #region PrintText Action<string, Action> PrintText = (text, done) => { Talk.AttachToDocument(); Talk.load(); Talk.volume = Math.Min(1, dude.Zoom.DynamicZoom / 4); Talk.play(); Talk = new Talk { autobuffer = true }; text.Length.Range().AsyncForEach( i => { Wallpaper.innerText = text.Left(i + 1); var c = text[i]; if (LoadedScene.SlowText.Contains("" + c)) return 100.Random(); return 50.Random(); }, done ); }; #endregion Action<string, Action> PrintRandomText = (text, done) => PrintText(text.Split(LoadedScene.TextDelimiter).Randomize().First(), done); dude.DoneWalking += delegate { // compiler bug: cannot invoke Action<func, action> delegate ? System.Console.WriteLine("done walking in " + CurrentFrame.Name + " at " + dude.CurrentLocation); var xFirstOrDefault = Doors.FirstOrDefault(d => d.Condition()); System.Console.WriteLine("done walking in " + new { xFirstOrDefault }); // Doors null? if (TryToChangeRooms(xFirstOrDefault)) return; if (CurrentFrame.Items != null) { var item = CurrentFrame.Items.Where( i => new Point(i.X.ToInt32(), i.Y.ToInt32()).GetRange(dude.CurrentLocation) < i.R.ToInt32() ).FirstOrDefault(); if (item != null) { dude.IsSelected = false; dude.LookDown(); PrintRandomText(item.Text, delegate { dude.WalkingOnce += delegate { Wallpaper.innerText = ""; }; dude.IsSelected = true; } ); } } }; #region AnimateRoomChange AnimateRoomChange = ReadyToTeleport => { var Step1 = default(System.Action); var Step2 = default(System.Action); var Step3 = default(Action); Step1 = delegate { tween.Done -= Step1; ReadyToTeleport(); tween.Done += Step2; ShowRoom(); }; Step2 = delegate { tween.Done -= Step2; dude.DoneWalking += Step3; dude.IsWalking = true; }; Step3 = delegate { dude.DoneWalking -= Step3; dude.IsSelected = true; }; dude.IsSelected = false; tween.Done += Step1; // go left HideRoom(); // http://stackoverflow.com/questions/3009888/autoplay-audio-files-on-an-ipad-with-html5 ChangeRoom.AttachToDocument(); ChangeRoom.load(); ChangeRoom.volume = 0.2; ChangeRoom.play(); ChangeRoom = new ChangeRoom(); }; #endregion var pointer_x = 0; var pointer_y = 0; #region onmousemove Container.onmousemove += ev => { if (Native.Document.pointerLockElement == Container) { if (dude.IsSelected) { var volume = Math.Min(1, dude.Zoom.DynamicZoom / 4); var balance = dude.CurrentLocation.X / ViewSize.Width; pointer_x += ev.movementX; pointer_y += ev.movementY; pointer_x = Math.Min(ViewSize.Width - 0, Math.Max(0, pointer_x)); pointer_y = Math.Min(ViewSize.Height - 0, Math.Max(0, pointer_y)); var OffsetPosition = new Point(pointer_x, pointer_y ); Console.WriteLine(OffsetPosition); Argh_Stereo(volume, balance); dude.WalkTo(OffsetPosition); } } }; #endregion #region ontouchstart Container.ontouchstart += ev => { ev.preventDefault(); System.Console.WriteLine(ev.CursorPosition); if (dude.IsSelected) { var volume = Math.Min(1, dude.Zoom.DynamicZoom / 4); var balance = dude.CurrentLocation.X / ViewSize.Width; var ev_OffsetPosition = new Point( ev.touches[0].clientX - Container.Bounds.Left, ev.touches[0].clientY - Container.Bounds.Top ); Argh_Stereo(volume, balance); dude.WalkTo(ev_OffsetPosition); } }; #endregion #region onclick Container.onclick += ev => { ev.preventDefault(); if (ev.MouseButton == IEvent.MouseButtonEnum.Middle) { if (Native.Document.pointerLockElement == Container) { Native.Document.exitPointerLock(); return; } pointer_x = (int)dude.CurrentLocation.X; pointer_y = (int)dude.CurrentLocation.Y; //Container.requestFullscreen(); Container.requestPointerLock(); return; } if (ev.Element != Ground) return; System.Console.WriteLine(ev.CursorPosition); if (dude.IsSelected) { var volume = Math.Min(1, dude.Zoom.DynamicZoom / 4); var balance = dude.CurrentLocation.X / ViewSize.Width; Argh_Stereo(volume, balance); dude.WalkTo(ev.OffsetPosition); } }; #endregion //GroundOverlay.onclick += // ev => // { // if (ev.Element != GroundOverlay) // return; // System.Console.WriteLine(ev.CursorPosition); // if (dude.IsSelected) // { // new Argh().play(); // dude.WalkTo(ev.OffsetPosition); // } // }; dude.TeleportTo(ViewSize.Width / 2, (ViewSize.Height - MarginSafe) / 2); dude.LookDown(); ShowRoom(); dude.DoneWalkingOnce += delegate { PrintRandomText( LoadedScene.IntroText, delegate { dude.WalkingOnce += delegate { Wallpaper.innerText = ""; }; dude.IsSelected = true; } ); }; dude.WalkToArc(MarginSafe, dude.Direction); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { changeRoomScript = ChangeRoom.changeRoomInst; changeRoomScript.GoToRoom(roomIndex); }
void msgServer_RequestChangeRoom(object sender, MsgServerEventArgs e) { ChangeRoom changeRoom = e.obj as ChangeRoom; if (changeRoom.type == type.New && e.RequestUser.CreatedRoomsCount < e.RequestUser.CreateRooms)//如果请求创建群 { #region 创建群 //10次随机产生群号(所谓摇号),如果10次摇出的群号都已被创建,则退出并表示服务器忙 //10都不能摇到空号表示用户运气不好,下次再试! for (int i = 0; i < 10; i++) { Random ran = new Random(); int RandKey = ran.Next(10000, 1000000000); //开始摇号,群号码从10000至1000000000随机产生 if (!Rooms.ContainsKey(RandKey.ToString())) //如果是空号,以此号创建群 { Room room = new Room(); room.RoomID = RandKey.ToString(); room.RoomName = changeRoom.RoomName; room.Notice = changeRoom.Notice; room.UserIDs = changeRoom.UserIDs; room.CreateUserID = e.RequestUser.UserID; //创建者为请求者 e.RequestUser.CreatedRoomsCount++; //标记用户创建群数 #region 将内存中的用户添加到内存中的群 string[] userids = room.UserIDs.Split(';'); foreach (string userID in userids) { UserVcard user = getUser(userID); if (user != null) { if (room.Users == null) { room.Users = new Dictionary <string, User>(); } if (!room.Users.ContainsKey(userID)) { room.Users.Add(user.UserID, user); } if (user.Rooms == null) { user.Rooms = new Dictionary <string, Room>(); } if (!user.Rooms.ContainsKey(room.RoomID)) { user.Rooms.Add(room.RoomID, room); } } } room.UserIDs = "";//重新生成群包含的Users foreach (User u in GetUsers(room)) { room.UserIDs += u.UserID + ";"; } #endregion Rooms.Add(room.RoomID, room); //将创建的群添加到内存 DBHelper.CreateRoom(room); //将创建的群添加到数据库 changeRoom.RoomID = room.RoomID; changeRoom.CreateUserID = room.CreateUserID; SendMessageToRoom(room.CreateUserID, room, Factory.CreateXMLMsg(changeRoom)); //发送消息到刚创建的群,通知群里的用户已经加入群 return; //创建群成功,退出 } } #endregion } else if (changeRoom.type == type.set)//请求更新群 { #region 更新群 Room room = getRoom(changeRoom.RoomID); if (room != null && room.CreateUserID == e.RequestUser.UserID)//如果群创建者为请求用户 { string oldVersion = room.RoomName.Trim() + room.Notice.Trim() + room.UserIDs; changeRoom.CreateUserID = room.CreateUserID; room.Notice = changeRoom.Notice; room.RoomName = changeRoom.RoomName; string[] newUserids = changeRoom.UserIDs.Split(';'); #region 查找群中被删除的用户 changeRoom.type = type.delete; //标识删除群 changeRoom.UserIDs = null; //不要将新群包含的用户通知退出群的用户 string delRoomMsg = IMLibrary3.Protocol.Factory.CreateXMLMsg(changeRoom); bool t = false; foreach (UserVcard user in GetUsers(room)) { t = false; foreach (string userID in newUserids) { if (user.UserID == userID)//如果群里的用户在更新后的用户集合中存在,则表示未删除 { t = true; } } if (!t)//如果更新的用户集合中没有当前用户,则表示从群中删除此用户 { room.Users.Remove(user.UserID); user.Rooms.Remove(room.RoomID); SendMessageToUser(user, delRoomMsg);//通知用户退出群 } } #endregion #region 添加新用户记录群中新用户 foreach (string userID in newUserids) { UserVcard user = getUser(userID);//获取新用户 if (user != null) { if (!room.Users.ContainsKey(user.UserID)) { room.Users.Add(user.UserID, user);//如果群里无此用户,则新增用户 if (!user.Rooms.ContainsKey(room.RoomID)) { user.Rooms.Add(room.RoomID, room);//如果用户不在此群,则为用户新增群 } } } } #endregion room.UserIDs = "";//重新生成群包含的Users foreach (User u in GetUsers(room)) { room.UserIDs += u.UserID + ";"; } changeRoom.type = type.set; //标识群信息被成功修改 changeRoom.UserIDs = room.UserIDs; //设置最新用户列表 string newVersion = room.RoomName.Trim() + room.Notice.Trim() + room.UserIDs; if (oldVersion == newVersion) { return; //如果没有做任何更改 } SendMessageToRoom(room.CreateUserID, room, Factory.CreateXMLMsg(changeRoom)); //通知群内原用户,群信息已经修改 DBHelper.UpdateRoom(room); } #endregion } }
public ChangeRoomWrapper(ChangeRoom cr) { line = cr; }